diff --git a/examples/NetCore2/HostingExample/Program.cs b/examples/NetCore2/HostingExample/Program.cs index 12596eb4..e927b388 100644 --- a/examples/NetCore2/HostingExample/Program.cs +++ b/examples/NetCore2/HostingExample/Program.cs @@ -23,10 +23,14 @@ private static async Task Main() try { + logger.Info("Message before configure host builder"); var hostBuilder = new HostBuilder() - .ConfigureLogging(builder => builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace)) - .ConfigureServices((hostContext, services) => services.AddHostedService()) - .UseNLog(); + .ConfigureLogging(builder => + { + builder.AddNLog(logger.Factory.Configuration); + builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); + }) + .ConfigureServices((hostContext, services) => services.AddHostedService()); // Build and run the host in one go; .RCA is specialized for running it in a console. // It registers SIGTERM(Ctrl-C) to the CancellationTokenSource that's shared with all services in the container. diff --git a/examples/NetCore2/HostingExample/nlog.config b/examples/NetCore2/HostingExample/nlog.config index 42c67950..b991733c 100644 --- a/examples/NetCore2/HostingExample/nlog.config +++ b/examples/NetCore2/HostingExample/nlog.config @@ -10,7 +10,9 @@ + layout="${date}|${level:uppercase=true}|${message} ${exception:format=tostring}|${logger}|${all-event-properties}" + header="Header" + WriteHeaderWhenInitialFileNotEmpty="true"/> diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index 2d691053..277693eb 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -77,7 +77,7 @@ List of major changes in NLog 5.0: https://nlog-project.org/2021/08/25/nlog-5-0- - +