serilog / serilog-sinks-debug

Writes Serilog events to the debug output window
Apache License 2.0
33 stars 10 forks source link

Debug logs not appearing without explicity setting minimum level #17

Open Reeceeboii opened 4 weeks ago

Reeceeboii commented 4 weeks ago

I am having a strange issue where LogEventLevel.Debug logs (or those written directly via Log.Debug()) do not show in the Debug console, unless .MinimumLevel.Debug() is applied to the global logger, despite the fact that the extension's default restrictedToMinimumLevel parameter is defaulted to LevelAlias.Minimum so the sink itself should be actioning debug level logs.

Configuring logger:

Logging.cs

[Conditional("DEBUG")]
public static void ConfigureDebugLogging()
{
    Log.Logger = new LoggerConfiguration()
        .WriteTo.Debug()
        .CreateLogger();
}

App.xaml.cs

Logging.ConfigureDebugLogging();

Log.Debug("Logging has started");
Log.Information("Logging has started");

Debug console: image

Confusingly, this starts to work if I apply a .MinimumLevel.Debug() chain to the logger initialisation:

[Conditional("DEBUG")]
public static void ConfigureDebugLogging()
{
    Log.Logger = new LoggerConfiguration()
        .WriteTo.Debug()
        .MinimumLevel.Debug()
        .CreateLogger();
}

image

...but not if this is applied to the sink itself (which I would assume to be redundant as the sink defaults to this anyway):

[Conditional("DEBUG")]
public static void ConfigureDebugLogging()
{
    Log.Logger = new LoggerConfiguration()
        .WriteTo.Debug(restrictedToMinimumLevel: LogEventLevel.Debug)
        .CreateLogger();
}

image

Running version 3.0.0 of this package inside a .NET 8.0 WPF Solution.

bartelink commented 4 weeks ago

The overall log configuration also has a minimum level that's the first level of filtering - the default for that is Information, hence the MinimumLevel.Debug() making the difference.

After that, each sink to which events are being written can impose a more restrictive filter at the point of entry - i.e. the default you are referring to is being applied, but you're correct that the restrictedToMinimumLevel: LogEventLevel.Debug) has no real effect (though IIRC that would still cause the sink not to emit a Verbose message, assuming the top level pipeline was configured with that as its minimum level).


NOTE: in future, you're best off asking usage questions like this on stackoverflow.com as the template suggests; you'll normally get much quicker answers, and the issue tracker has one less issue...

Reeceeboii commented 4 weeks ago

Gotcha, thanks.

However, I do question why the README in this repo shows DBG logs in the screenshot of the console window when the code in the blocks above it will not be able to produce any DBG level logs (this is the code I was going by while integrating this library to my codebase).

It's mighty confusing that a debug log sink's setup instructions do not allow the production of debug level logs out of the box without extra logger config that isn't directly documented (unless it is documented and I'm blind).

bartelink commented 4 weeks ago

Oh, that's a good catch in that instance - a PR to fix the readme would be much appreciated.

I can remember being confused by the default minimum level and why stuff wasnt appearing myself, though the default does make sense to me in terms of trying to keep logs sane.