1

Using Serilog and Serilog.Settings.Configuration in .NET Core 2, I'd like to do something like the following. Is it possible?

appsettings.json

{
  "Serilog": {
    "MinimumLevel": {
      "ControlledBy": {
        "Serilog.Core.LoggingLevelSwitch": "Debug"
      }
    }
  }
}

program.cs

var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", reloadOnChange: true)
    //...
    .Build();

Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    //...
    .CreateLogger();

My intent is to modify the config file and have the log level change without restarting the application.

Dave
  • 332
  • 1
  • 7

1 Answers1

1

This works straight out of the box with the normal "MinimumLevel": "Debug" syntax.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101