You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No matter the configuration and how the log4net provider is registered, the middleware debug logs are not showed. Lets assume we have the following section in appsettings.json (we must explicitly define the Debug section, otherwise this provider has default level of Information). In this configuration we will notice a lot of debug messages from the middleware (routing configuration, entity framework migration logs, razor logs etc)
Now, no matter how we register the log4net provider, these debug messages will never reach this provider. Just as an example, in the following output we see that Info level is forwarded but not the debug logs
The platform is AspNet Core 2.2, and I have set the minimum level programmatically. I tested adding the provider during the host building process, I altered the IServiceCollection collection, altered the ILoggerFactory configuration. None of these worked.
Do anyone have any idea, anyone found a solution? or it's just me missing something :)
It's easy to replicate the issue, but anyway if you can't I'll set up a repository.
The text was updated successfully, but these errors were encountered:
As soon I posted the issue, I found a solution :) I'm posting the answer, if anybody needs it.
We have to explicitly define the filters programmatically as following.
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging((hostingContext, logging) =>
{
//I assumed if clearing the providers, may clear the filter configuration, but it turned out it doesnt matter.
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Debug);
//This won't work, no matter that you properly have configured everything.
//logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddFilter("Default", LogLevel.Debug);
logging.AddFilter("Microsoft", LogLevel.Debug);
logging.AddFilter("System", LogLevel.Debug);
//I'm adding the debug provider, just so we can compare, in production you can exclude it.
logging.AddDebug();
logging.AddLog4Net();
});
}
No matter the configuration and how the log4net provider is registered, the middleware debug logs are not showed. Lets assume we have the following section in appsettings.json (we must explicitly define the Debug section, otherwise this provider has default level of Information). In this configuration we will notice a lot of debug messages from the middleware (routing configuration, entity framework migration logs, razor logs etc)
Now, no matter how we register the log4net provider, these debug messages will never reach this provider. Just as an example, in the following output we see that Info level is forwarded but not the debug logs
The platform is AspNet Core 2.2, and I have set the minimum level programmatically. I tested adding the provider during the host building process, I altered the IServiceCollection collection, altered the ILoggerFactory configuration. None of these worked.
Do anyone have any idea, anyone found a solution? or it's just me missing something :)
It's easy to replicate the issue, but anyway if you can't I'll set up a repository.
The text was updated successfully, but these errors were encountered: