Search code examples
asp.netasp.net-coreloggingserilog

How to use Logging level parameter from appsettings.json for Serilog?


When i am trying to use Logging inside appsettings.json for config Serilog, it is ingore my LovLevel option.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Warning"
    },
    "FilePath": "Loggs//log.log"
  }
}

I can only fix it with adding MinimumLevel option:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Warning"
    },
    "MinimumLevel": {
      "Default": "Debug"
    },
    "FilePath": "Loggs//log.log"
  }
}

Can i setup my minlevel of logs without adding "MinimumLevel" option and use "LowLevel" instead?


Solution

  • You need to set Default as your MinimumLevel.

    E.g.

    {
      "Logging": {
        "LogLevel": {
          "Default": "Debug",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Warning"
        },
        "FilePath": "Loggs//log.log"
      }
    }