I am setting an override in the appsettings.json
like this:
"Microsoft.AspNetCore.Hosting.Diagnostics": "Warning"
However, I’m still getting logged events at the Information
level where RenderedMessage
and MessageTemplate
is:
Microsoft.AspNetCore.Hosting.HttpRequestIn
and the SourceContext
is empty. Usually this is namespace.
The current appsettings.json
is as follows:
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft.AspNetCore.Hosting.Diagnostics": "Warning",
}
}
}
So if the override is not working, how can I ignore these events?
EDIT
I currently added the following to exclude specific events:
"Using": [
"Serilog.Sinks.Http",
"Serilog.Expressions"
],
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "StartsWith(@m, 'Microsoft.AspNetCore.Hosting.HttpRequestIn')"
}
}
]
However, the overrides should work and there is no need to use a filter.
1
Serilog does not use the default logging configuration section, try moving the setup to Serilog
-> MinimumLevel
-> Override
:
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft.AspNetCore.Hosting.Diagnostics": "Warning"
}
},
Also check out:
Serilog.Settings.Configuration
docs how to configure it from the configuration- The MinimumLevel, LevelSwitches, overrides and dynamic reload section of the docs.
- How to override Root section name used by Serilog, but note it has different structure then the default one.
- Serilog integration with ASP.NET Core
2