Author : MD TAREQ HASSAN

Available configuration options

{
    "Serilog": {
      "Using": [],
      "MinimumLevel": "",
      "WriteTo": [
          { 
            "Name": "",
            "Args": { "": "" }
          }
      ]
      "Enrich": [],
      "Destructure": [],
      "Properties": {
      }
    }
}

See

Using

Sink names as array

{
    "Serilog": {
      "Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async", "Serilog.Sinks.Seq"],
    }
}

Notes

MinimumLevel

Default Level: Information

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning"
      }
    },
  }
}

Fluent API

Log.Logger = new LoggerConfiguration()
	.MinimumLevel.Information()
	.MinimumLevel.Override(MicrosoftLog, Warning)
	.MinimumLevel.Override(SystemtLog, Warning)
	.WriteTo.XXX()
	.CreateLogger();

See:

Overriding MinimumLevel Per Sink

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .WriteTo.File("log.txt")
    .WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Information)
    .CreateLogger();

Output template

appsettings.json

{
    "Serilog": {

      "WriteTo": [
        { 
            "Name": "sink_name",
            "Args": {
              "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}",
            }
        },
      ]
    }
}

There is special handling for Log level with w|u|t)[1-4]

Sample Configuration

appsettings.Development.json

{
  "Serilog": {
    "MinimumLevel": "Warning",
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "outputTemplate": "[{Timestamp:yyyy/MM/dd HH:mm:ss} {Level:u10}] {Message:lj} {NewLine}{Exception}{NewLine}",
          "theme": "Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme::Literate, Serilog.Sinks.Console"
        }
      },
      {
        "Name": "File",
        "Args": {
          "outputTemplate": "[{Timestamp:yyyy/MM/dd HH:mm:ss} {Level:u10}] {Message:lj} {NewLine}{Exception}{NewLine}",
          "path": "C:/Serilog/test.txt",
          "shared": "true",
          "fileSizeLimitBytes": "1000000",
          "rollOnFileSizeLimit": true,
          "flushToDiskInterval": "1"
        }
      }
    ]
  }
}