You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to use the AddSerilog() extension method to add Serilog logging in my builder but found that any filtering I apply is overridden in the extension method, for example:
services.AddLogging(l => l.AddFilter((cat, lev) =>
{
// Filter information logs from Sample.Program
if (cat.StartsWith("Sample.Program"))
{
return lev >= LogLevel.Warning;
}
// else informational only
return lev >= LogLevel.Information;
})
.AddConsole()
);
services.AddLogging(l => l.AddFilter((cat, lev) =>
{
// Filter out all EF logs to stop it being so chatty
if (cat.StartsWith("Sample.Program"))
{
return lev >= LogLevel.Warning;
}
// else informational only
return lev >= LogLevel.Information;
})
.AddConsole()
.AddSerilog()
);
I see both messages from the serilog logger and only the warning message from the .net logger:
[08:47:47 INF] Information
[08:47:49 WRN] Warning
warn: Sample.Program[0]
Warning
this seems to be due to this this line If I comment that line out then filtering works as expected. Was this left for debugging purposes? Should it be controlled via a parameter to the method? It doesn't seem like it is needed since you can control filtering outside.
The text was updated successfully, but these errors were encountered:
You can read some of the discussion regarding this in #98.
The eventual result of working through this was Serilog.AspNetCore's UseSerilog() and the related instructions in that README; see alternatively Serilog.Extensions.Hosting if you're not in a web app.
If your app's a plain console app, then configuring everything via Serilog (sinks, levels, filters, etc.) and just using Microsoft.Extensions.Logging as a logging abstraction will be a better experience. Let us know if you need more details on this.
I've been trying to use the AddSerilog() extension method to add Serilog logging in my builder but found that any filtering I apply is overridden in the extension method, for example:
then
displays only the warning message:
If I add
.AddSerilog()
like this:I see both messages from the serilog logger and only the warning message from the .net logger:
this seems to be due to this this line If I comment that line out then filtering works as expected. Was this left for debugging purposes? Should it be controlled via a parameter to the method? It doesn't seem like it is needed since you can control filtering outside.
The text was updated successfully, but these errors were encountered: