Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug logs not appearing without explicity setting minimum level #17

Open
Reeceeboii opened this issue Aug 17, 2024 · 3 comments · May be fixed by #18
Open

Debug logs not appearing without explicity setting minimum level #17

Reeceeboii opened this issue Aug 17, 2024 · 3 comments · May be fixed by #18

Comments

@Reeceeboii
Copy link

Reeceeboii commented Aug 17, 2024

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
Copy link
Member

bartelink commented Aug 17, 2024

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
Copy link
Author

Reeceeboii commented Aug 17, 2024

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
Copy link
Member

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.

Reeceeboii added a commit to Reeceeboii/serilog-sinks-debug that referenced this issue Aug 18, 2024
Added instructions for chaining debug level call.
Also the same for the XML and JSON config.
@Reeceeboii Reeceeboii linked a pull request Aug 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants