Different Minimum Level Logs Serilog
Working from the answers above, this is how I set it up in code as opposed to config
LoggerConfiguration GetConfig()
=> new LoggerConfiguration()
.WriteTo.Seq(serverUrl: "http://localhost:5341", restrictedToMinimumLevel: LogEventLevel.Debug)
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Error);
var logger = GetConfig().CreateLogger();
builder.RegisterInstance(logger).As<ILogger>();
After I did this, it worked for log level Information and above. Debug didn't work. This post explained why.
I had to set a 'global' minimum level like this.
LoggerConfiguration GetConfig()
=> new LoggerConfiguration()
.WriteTo.Seq(serverUrl: "http://localhost:5341", restrictedToMinimumLevel: LogEventLevel.Debug)
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Error)
.MinimumLevel.Verbose();
The setting you're looking for is restrictedToMinimumLevel
. This GitHub issue shows some examples of this, but for your example, you just need to add restrictedToMinimumLevel
to your Args
for RollingFile
:
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "RollingFile",
"IsJson": true,
"Args": {
"pathFormat": "C:\\Logs\\Log-{Hour}.json",
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
"restrictedToMinimumLevel": "Warning"
}
},
{
"Name": "Console"
}
]
},