I'm using EF Core and it logs quite a few "info" level messages on application start that I want to filter out. The docs imply that a filtering rule specifying a category should match all categories starting with that category (i.e. "Microsoft"
matches "Microsoft*"
.)
My application has the default logging setup via CreateDefaultWebBuilder
and so I placed the following in my appsettings.json
:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning",
"Microsoft": "Warning"
}
}
Contrary to my expectation, this did not work. However, the following did:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning",
"Microsoft.EntityFrameworkCore.Migrations": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning",
"Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager": "Warning",
"Microsoft.EntityFrameworkCore.Infrastructure": "Warning"
}
}
What am I doing wrong? Surely I shouldn't need to list every category explicitly?
The default ASP.NET Core templates already come with both an appsettings.json
and a appsettings.Development.json
. The latter file is an environment-specific one which will apply on top of the default if you are running in Development
mode.
You are correct that a configuration key "Microsoft"
will apply to all Microsoft.*
namespaces. But only if there isn’t a more specific one, i.e. the most-specific configuration will win.
The default development settings file will set the Microsoft
prefix to Information
and the default to Debug
. This will overwrite what you have specified in the appsettings.json
, so the effective level for Microsoft
will still be the default Information
. Only when you use more specific namespaces, you can overwrite the setting from the development settings configuration.
In the end, you should make sure you are editing the right file. appsettings.json
should contain those configurations that apply to any environment. These should basically be the production defaults. The appsettings.Development.json
should then be used when you want a different configuration during development only. So it’s likely that you want to edit this here.