datalust/serilog-sinks-seq

WriteTo.Seq(..) doesn't respect MinimumLevel.Override

stephanprobst opened this issue ยท 5 comments

I'm configuring Serilog with Seq like that:

hostBuilder.UseSerilog((builder, loggerConfiguration) =>
            {
                var env = builder.HostingEnvironment;
                var seqConfig = builder.Configuration.GetSection("Seq");

                var loggingLevelSwitch = new LoggingLevelSwitch();

                loggerConfiguration.MinimumLevel.ControlledBy(loggingLevelSwitch)
                                   .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                                   .MinimumLevel.Override("BeatPulse", LogEventLevel.Warning)
                                   .Enrich.FromLogContext()
                                   .Enrich.WithMachineName()
                                   .Enrich.WithEnvironmentUserName()
                                   .Enrich.WithProperty("Environment", env.EnvironmentName)
                                   .WriteTo.Console()
                                   .WriteTo.Seq(url ?? seqConfig["Url"], apiKey: apiKey ?? seqConfig["ApiKey"], controlLevelSwitch: loggingLevelSwitch);
            });

The console sink respects the override and doesn't prompt messages from Microsoft and BeatPulse.
Unfortunately the Seq-Sink does not.

I'm not sure if it's a wrong config or it isn't supported yet?

Hi @stephanprobst, thanks for the note.

Not sure what could be happening here - the minimum level overrides are completely governed by the logging pipeline, not the sink. The sink will just store whatever log events reach it - so generally the Seq sink and console sink will show exactly the same thing in this configuration. Can you spot any other clues?

Cheers,
Nick

Hey @nblumhardt ,

thank you for your quick reply. I tried to do it in ConfigureLogging extension and set Log.Logger and builder.ClearProviders().AddSerilog(..) explicit instead of UseSerilog(..) and the overrides are still ignored in Seq while the output is omitted on the console.

But with your explanation it would be weird to have such a behavior. So it has to be something on my side.
To make it clear: The overrides should be applied when the levelSwitch has a lower LogEventLevel?

The whole Enrichers are applied to the seq output but the MinimumLevel seems to be ignored.

Thanks for the follow-up; I'm still scratching my head on this one, I'll try to reproduce it here ๐Ÿ‘

Hey @nblumhardt ! I finally found it.
We had multiple clients which logged to the same seq instance (which wasn't intended in this case). It resulted in a view where you could think that the logging doesn't work. Infact I looked at messages from a different client.
So I have to apologize. It was all my fault. Many thanks for your help and work!

Awesome, glad it turned out to be something simple ๐Ÿ‘