Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable DEBUG level logs of the Microsoft.AspNetCore namespace

I'm using log4net in my ASP.net Core application, and have the following configurations:

// Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureLogging((logging) => {
            logging.ClearProviders();
            logging.AddLog4Net();
        }).UseStartup<Startup>();

My config:

<log4net>
    <appender name="Console" type="log4net.Appender.ConsoleAppender">
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%-5date %-5level [%thread] %type.%method:%line - %message%newline" />
        </layout>
    </appender>
    
    <!-- log everything coming from AspNetCore -->
    <logger name="Microsoft.AspNetCore" additivity="false">
        <level value="Debug" />
        <appender-ref ref="Console" />
    </logger>
    
    <root>
        <level value="Info" />
        <appender-ref ref="Console" />
    </root>
</log4net>

What I want to achieve:

  • Disable log messages I see in my Azure app-service (many HTTP GET and HTTP POST logs, probably coming from the IIS logs)
  • Have DEBUG level logs of anything coming from Microsoft.AspNetCore

What am I missing? If I'm using log4net, do I still need the "Logging" section in the appsettings.json file? If I add the following, I will be able to see the logs, but why is it needed? Shouldn't this be controlled from the log4net.conf file?

"Logging": {
  "LogLevel": {
     "Microsoft": "Debug"
  }
}
like image 743
Maroun Avatar asked Oct 27 '25 14:10

Maroun


1 Answers

The logging levels messages below the Information level for a development build you must make allowances for it in the appsettings.Development.json as specified in the documentation and illustrated below:

{
     "Logging": {
         "LogLevel": {
             "Default": "Debug",
             "...":"..."
          }
     }
}

See here

By default appsettings.json file will be generated in Asp.net core applications.

Logging configuration is commonly provided by the Logging section of appsettings.{Environment}.json files. appsettings.Development.json file is generated by the ASP.NET Core web app templates:

{
    "Logging": {
        "LogLevel": {
            "Default": "Information",
            "Microsoft": "Debug",
            "Microsoft.Hosting.Lifetime": "Information"
          }
     }
}

The logging categories are

If the "default" log level is not set, the default log level value is Information.

The "Microsoft" category logs at log level Debug and higher.

The "Microsoft.Hosting.Lifetime" category logs at log level "Information" and higher.

The log level follows:

Trace = 0, Debug = 1, Information = 2, Warning = 3, Error = 4, Critical = 5, and None = 6.

Refer here for more info

Check here for disable the IIS logs

like image 114
Delliganesh Sevanesan Avatar answered Oct 30 '25 03:10

Delliganesh Sevanesan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!