Author : HASSAN MD TAREQ

Available configuration options

  • AuditTo: An optional feature of Auditing events not generally used with async style sinks (HTTP destinations).
  • Destructure: The ability to destructure events via message templates (https://messagetemplates.org)
  • Enrich: Used to add property data related to a specific event. Enrichers will implement ILogEventEnricher.
  • Filter: A filter will implement ILogEventFilter in order to filter events based on log event data.
  • ReadFrom: A way of applying configuration to the log configuration, common examples include from configuration files.
  • WriteTo: The way sinks are wired into the pipeline, as per the console example above. Sinks implement the ILogEventSink interface.
{
    "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

  • ‘Using’ become redundant when ‘WriteTo’ is used
  • ‘Using’ is for sinks without configuration, ‘WriteTo’ is for sinks with configuration

MinimumLevel

Default Level: Information

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Debug",
        "System": "Debug"
      }
    },
  }
}

See:

Overriding MinimumLevel Per Sink

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

Output template

  • log-event properties and properties attached using enricher
  • {LogEvent.Prop} => {Timestamp}
  • {LogEvent.Prop:<format_specifier>} => {Timestamp:HH:mm:ss}

appsettings.json

{
    "Serilog": {

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