How can I get "controlLevelSwitch" to work in the Serilog Seq sink

1k Views Asked by At

I have my application set up with Serilog logging and the Seq sink (in addition to a ColoredConsole and a RollingFile sink). Everything is working great but the minimum log level switching from Seq.

My logging level switch is set up with a starting minimum level of "Verbose" to make sure anything is sent to seq.

In the settings for the API key the minimum level is set to "Debug" and seq only shows events with level "Debug" and higher as expected.

But on the application side everything is still logged, no change in min log level. I can see "Verbose" on the console, the rolling log file of the seq sink and the separate rolling log file I set up. This doesn't change whether I send "Debug" level events that are picked up by seq or wait a few minutes.

This is my config:

var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Verbose);
Log.Logger = new LoggerConfiguration()
    .MinimumLevel.ControlledBy(levelSwitch)
    .Enrich.WithExceptionDetails()
    .WriteTo.ColoredConsole()
    .WriteTo.RollingFile(@".\log\log-{Date}.txt")
    .WriteTo.Seq("http://localhost:5341", bufferBaseFilename: @".\temp\seqlog", apiKey: "...", controlLevelSwitch: levelSwitch)
    .CreateLogger();

Log.Logger.Verbose("TEST!!!");
1

There are 1 best solutions below

3
On

The switch won't be set by the Seq sink until some events have already reached Seq - the level control is not instantaneous. In practice this might mean a few seconds have to elapse before you'll see a change in output from the other sinks.