In the Startup
class of my project I have the following Configure
method:
private void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
loggerFactory.AddNLog();
...
}
This worked OK in .NET Core 2.2, but after upgrading to 3.0, I get the warning Method 'NLog.Extensions.Logging.ConfigureExtenstions.AddNLog' is obsolete: instead use ILoggingBuilder.AddNLog() or IHostBuilder.UseNLog().
So I tried to update the method to
private void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggingBuilder loggingBuilder)
{
...
loggingBuilder.AddNLog();
...
}
or
private void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostBuilder hostBuilder)
{
...
hostBuilder.UseNLog();
...
}
But in both cases I got a DI exception: Could not resolve a service of type {Microsoft.Extensions.Logging.ILoggingBuilder/Microsoft.Extensions.Hosting.IHostBuilder} for the parameter {loggingBuilder/hostBuilder} of method 'Configure' on type 'MyProject.Startup'
.
I could not find any viable source on how to change the NLog configuration fro .NET Core 3.0 and there is nothing about logging in the official Microsoft guide. Does anyone know how to solve this issue?
With ASP.NET Core 2+, the pattern to bootstrap an ASP.NET Core site has changed. NLog adapts that. With the latest version of NLog.Extensions.Logging.ConfigureExtenstions
, the old methods are made obsolete.
For example, ASP.NET Core nowadays uses a CreateHostBuilder
.
I would recommend to follow:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With