# Elastic.Serilog.Sinks minimum log level is not respected

**URL:** <https://discuss.elastic.co/t/elastic-serilog-sinks-minimum-log-level-is-not-respected/361810>\
**Category:** Elastic Observability\
**Created:** [June 20, 2024, 10:09pm UTC](https://discuss.elastic.co/t/elastic-serilog-sinks-minimum-log-level-is-not-respected/361810 "2024-06-20T22:09:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LukasT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukast/32/131373_2.png) [@LukasT](https://discuss.elastic.co/u/LukasT)\
**Post date:** [June 20, 2024, 10:09pm UTC](https://discuss.elastic.co/t/elastic-serilog-sinks-minimum-log-level-is-not-respected/361810/1 "2024-06-20T22:09:25Z")

</div>

I am trying to implement logging in [ASP.Net](http://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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Alex\_Salgado-Elastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_salgado-elastic/32/103081_2.png) [@Alex\_Salgado-Elastic](https://discuss.elastic.co/u/Alex_Salgado-Elastic)\
**Post date:** [June 21, 2024, 12:22am UTC](https://discuss.elastic.co/t/elastic-serilog-sinks-minimum-log-level-is-not-respected/361810/2 "2024-06-21T00:22:32Z")

</div>

> [@LukasT](#):
>
> ```auto
> Host.UseSerilog((ctx, lc) => lc
> .MinimumLevel
> 
> ```

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.

> **[Logging with Serilog in .NET](https://dev.to/billy_de_cartel/logging-with-serilog-in-net-27h1)**
>
> Logging is an essential part of application development, as it allows developers to track and...

---

<div class="post-metadata">

**Author:** ![LukasT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukast/32/131373_2.png) [@LukasT](https://discuss.elastic.co/u/LukasT)\
**Post date:** [June 21, 2024, 11:46am UTC](https://discuss.elastic.co/t/elastic-serilog-sinks-minimum-log-level-is-not-respected/361810/3 "2024-06-21T11:46:12Z")

</div>

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.
