A fork published by MMPWorks to demonstrate migrating a real .NET application from Serilog to Herald. This repository is an unmodified copy of the upstream application except for the logging migration described below.
Original project net-daemon/netdaemon — write your Home Assistant automations in C# (a worker/daemon) Original author Tomas Hellström and the NetDaemon contributors License MIT — © 2019 Tomas Hellström. Preserved unchanged in LICENSE; all copyright remains with the original author.What MMPWorks changed Only the logging migration below, plus one host-boot fix that was NetDaemon's own bug (see the caveat). The framework itself is untouched.
Verdict: viable, with a localized bootstrap change. net10. The ~53 ILogger<T> call sites did not change — the migration lives in the logging bootstrap, not in your automations.
The migration is a package swap plus the logging bootstrap. The deployable Host pins the public Herald packages in place of Serilog:
// NetDaemon.Extensions.Logging.csproj
- <PackageReference Include="Serilog.AspNetCore" Version="..." />
+ <PackageReference Include="MMP.Herald.Serilog" Version="0.12.6" />
+ <PackageReference Include="MMP.Herald.Serilog.AspNetCore" Version="0.12.6" />This is a worker/daemon whose operator reads logs in a colored console. It ships a hand-built console color theme and an exact output template, so the migration had to carry both — the template the operator reads at a glance, and the per-token colors. It does.
We proved this on a live host run, not just a compile.
- The ~53
ILogger<T>call sites did not change. - The exact NetDaemon console template renders through
MessageTemplateTextFormatter— confirmed by the live host run. - The runtime
LoggingLevelSwitch, per-sourceMinimumLevel.Override, and log-context enrichment all carried. - Herald flushes on
ApplicationStopped— a small shutdown bonus the daemon gets for free. - The custom console color theme carries: the themed console sink ships in 0.12.6 with Serilog's real
AnsiConsoleThemeandSystemConsoleThemetypes — named presets (Code/Literate/Grayscale) and a public constructor for a custom per-token palette.WriteTo.Console(theme: …)compiles against the package swap with no rewrite. The colorization is pinned by the package's own ANSI-escape regression tests (CustomConsoleThemeTests, 7 passing): named themes emit the expected escapes, custom palettes render the exactLevelErrorcolor, and ANSI is suppressed on redirected output. - Tests: 447 passed, 0 failed, 0 skipped (unit suites, Release, 0.12.6). The themed console path is proven by the live run and the 7 ANSI-escape tests.
One blocker sat outside Herald. NetDaemon's own YAML config parser casts every YAML root to a mapping and throws on Home Assistant !include files whose root is a sequence (automations.yaml is []) — before any log line emits. That is NetDaemon's bug, not Herald's. We fixed it so the host boots, then the Herald pipeline emits live in NetDaemon's exact template. We state this rather than hide it: the one source change beyond the logging bootstrap is that host-boot fix, and it is unrelated to the logging migration itself.
Herald is Apache-2.0 open source: github.com/mmpworks/Herald.OSS.
The original project README follows, unchanged.
Welcome to the NetDaemon project!
NetDaemon is an application daemon that enables you to write powerful home automation scripts in C# for Home Assistant. This repository contains NetDaemon V5, the latest version of the framework.
NetDaemon was founded by @helto4real in 2020 as a personal project to explore the use of C# in Home Assistant. Early contributions from @Ludeeus helped integrate NetDaemon with Home Assistant. The project gained significant momentum when @FrankBakkerNl joined and introduced the HassModel API, which leverages code generation to create a user-friendly experience.
Currently, @helto4real and @FrankBakkerNl serve as the primary maintainers, though many others have contributed over the years.
To learn how to install and use NetDaemon, visit our official documentation:
NetDaemon allows you to write your automations easily and cleanly using C#.
[NetDaemonApp]
class MyApp
{
public MyApp(Entities entities)
{
LightEntity hallwayLight = entities.Light.HallwayLight;
BinarySensorEntity motionSensor = entities.BinarySensor.HallwayMotionSensor;
// Check state of entities directly
if (motionSensor.IsOn() && hallwayLight.IsOff()){
hallwayLight.TurnOn();
}
// Subscribe to changes in the state of the motion sensor
motionSensor.StateChanges()
.Where(e => e.New?.IsOn() ?? false)
.Subscribe(_ => hallwayLight.TurnOn());
}
}If you have issues or suggestions, please feel free to:
- Open an issue
- Join our Discord server for support, discussions, and contributions.
Contributions are welcome! If you'd like to help improve NetDaemon, we encourage you to join our Discord server to learn more about how you can contribute to the project.
Check out the Release Notes for detailed information on the latest changes, bug fixes, and new features.
NetDaemon is stable, and we're committed to maintaining that stability by minimizing breaking changes in future releases.
NetDaemon uses the CalVer versioning system for its NuGet packages. The version format is YYYY.WW.PATCH, where:
YYYY.WWrepresents the year and week number (01-52).PATCHindicates the patch version of the release.
- Visit the NetDaemon Developer Site for development resources.
To automatically upgrade all NuGet packages, use the dotnet-outdated-tool:
- Install the tool with the following command:
dotnet tool install --global dotnet-outdated-tool- Run this command to upgrade all packages:
dotnet outdated --pre-release Never --upgrade