I'm attempting to configure the loglevel of a custom ILogger<T>
through configuration. Is this easily possible? I want to restrict logging for this specific handler without touching any general settings.
In my custom case I'm injecting an ILogger<DataHandledLoggingHandler>
into my class, and would like to disable it in certain environments. What I assumed should work is to add a key "DataHandledLoggingHandler" to the Logging.LogLevel section of appsettings.json, to e.g. "None". However, I still see Warnings in my log sink. My appsetting.Development.json would look like this:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"DataHandledLoggingHandler": "None",
}
...
I've also attempted the fully qualified name including namespace, but still no luck, logging still takes place.
I do use Serilog with Seq and Console sink right now, but got it hooked up to ILogger through the Serilog.Extensions.Logging package
CodePudding user response:
First of all there is no None
option in Serilog's LogEventLevel
enum. Try using Fatal
for testing purposes. Also try specifying fully qualified name for DataHandledLoggingHandler
(i.e. with full namespace - SomeThing.Something1....DataHandledLoggingHandler
).
If this works but Fatal
is not enough then you will need to resort to setting up this via code - see this answer.