diff --git a/README.md b/README.md index ad2463f65..e8d4434e2 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ The following environment variables are available to identify your Home Assistan Example giving: ``` -docker run -d \ +docker run -dt \ --name netdaemon \ --restart=always \ -e HASS_HOST=192.168.1.1 \ diff --git a/src/Service/Program.cs b/src/Service/Program.cs index 06467ea7d..a44134e99 100644 --- a/src/Service/Program.cs +++ b/src/Service/Program.cs @@ -67,26 +67,31 @@ public static async Task Main(string[] args) .MinimumLevel.Is(Program.LogLevel) .WriteTo.Console(theme: AnsiConsoleTheme.Code) .CreateLogger(); + + CreateHostBuilder(args).Build().Run(); } catch (Exception e) { Log.Fatal(e, "Home assistant add-on config not valid json, ending add-on..."); - return; } - - CreateHostBuilder(args).Build().Run(); + finally + { + Log.CloseAndFlush(); + } } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureServices(services => { services.AddHostedService(); }) - .ConfigureLogging(logging => - { - logging.ClearProviders(); - // logging.AddConsole(options => options.IncludeScopes = false); - // logging.AddDebug(); - // logging.AddFilter("Microsoft", LogLevel.Error); - logging.AddSerilog(); - }); + .UseSerilog() + .ConfigureServices(services => { services.AddHostedService(); }); + // .ConfigureLogging(logging => + // { + // logging.ClearProviders(); + // // logging.AddConsole(options => options.IncludeScopes = false); + // // logging.AddDebug(); + // // logging.AddFilter("Microsoft", LogLevel.Error); + // logging.AddSerilog(); + // } + // ); } } \ No newline at end of file