0

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

Sossenbinder
  • 4,852
  • 5
  • 35
  • 78
  • Try adding the scopes to e.g. SimpleConsole logger. You can then see what the incoming log source is for your message. `services.AddLogging(builder => builder.AddSimpleConsole(opt => opt.IncludeScopes = true))` – Nsevens Jan 12 '23 at 13:36

1 Answers1

1

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.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • 1
    Thanks! What also worked for me in the end was to use SeriLog.MinimumLevel in my json instead of Logging.LogLevel – Sossenbinder Jan 12 '23 at 14:06