c# – How to set a different logging level in .NET Core

Question:

I can't figure it out, I'm doing everything right. But for some reason, .NET Core writes messages of the Information level to the logs. Although I explicitly specified in the settings to write only Error . Here is the part of Program.cs :

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
        })
        .Build();

appsettings.json looks like this:

"Logging": {
  "IncludeScopes": false,
  "LogLevel": {
    "Default": "Error"
  }
}

What am I doing wrong?

Answer:

I figured it out… The reason was that the appsettings.Development.json file was in the application directory and the logging settings were taken from it and not from appsettings.json , and this file was not visible in the VisualStudio browser, and I didn’t even think to go myself to the application directory and see what's there.

Where this file comes from and who created it is unclear.

Scroll to Top