Serilog filtering doesn't work as expected

49 views Asked by At

I'm trying to test Serilog filtering with a simple example, but it doesn't seem to read the string I provide correctly. When I use the "ByExcluding" method it doesn't exclude any logs, and when I use "ByIncludingOnly" it doesn't show any logs, which suggests that it simply doesn't understand what I wrote in the expression.

I have the Serilog.AspNetCore and Serilog.Expressions nuget packages installed.

This is what I tried:

using Serilog;

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .Filter.ByExcluding("@Level = 'Debug'")
    .WriteTo.Console()
    .WriteTo.File("logs/myapp.txt", rollingInterval: RollingInterval.Day)
    .CreateLogger();

Log.Information("Hello, Serilog!");
Log.Warning("This is a warning.");
Log.Debug("This is a debug message.");
Log.Error("This is an error.");

It's supposed to print all logs except the "Debug" one, but instead it prints all of them.

0

There are 0 answers