Elastic.Serilog.Sinks minimum log level is not respected

I am trying to implement logging in ASP.Net Core 8 application with serilog and the new Elastic.Serilog.Sinks (version 8.11.1) library and I am stuck with setting minimum log level. Here is the problematic part of my simple sample application:

var builder = WebApplication
    .CreateBuilder(args);

builder.Host.UseSerilog((ctx, lc) => lc
    .MinimumLevel.Debug()
    .WriteTo.Console()
    .WriteTo.Elasticsearch(new[] { new Uri("http://localhost:9200") }, opts =>
    {
        opts.MinimumLevel = Serilog.Events.LogEventLevel.Error;
        opts.BootstrapMethod = BootstrapMethod.Failure;
        opts.LevelSwitch = SwitchProvider.ElasticSwitch;
        opts.DataStream = new DataStreamName("logs", "web-api-example");
    }));

My SwitchProvider:

public static class SwitchProvider
{
    public static LoggingLevelSwitch ElasticSwitch = new LoggingLevelSwitch();
}

I would expect that only Error level logs and higher are published to Elasticsearch. However every log with level Debug and higher is persisted (I have same logs in console and in Elasticsearch). Also I have tried to switch the level at runtime with the LoggingLevelSwitch and nothing happens.

Am I missing something here?

Hi @LukasT ,

I don't know much about Serilog, but I have seen some examples where the minimum log level is set when instantiating the configuration class, as in the example below. See if it helps.

Thanks for you response. However the problem, imho, does not lie in the 'global' configuration of minimum level for Serilog, but in the minimum level set for the elasticsearch sink (first line of the sink configuration): opts.MinimumLevel = Serilog.Events.LogEventLevel.Error; - whatever I set here as the MinimumLevel it does not get reflected. In my example I set Error here and still logs with levels below Error are logged.