Closed avireddy02 closed 2 years ago
Wouldn't the restrictedToMinimumLevel
on the WriteTo.Console
call always mean that only things at Info or above get logged, regardless of the level overrides?
I was reading docs for Override and found below which means working as designed. I'm looking for something like AspNetCore Logging which supports writing debug for a specified Namespace/Full TypeName despite default LogLevel is as Info. This will help us identify issue much faster with fewer debug Logs.
Ex: While investigating a Routing Issue, adding Override for "Microsoft.AspNetCore.Routing.EndpointMiddleware" to Debug is lot helpful than setting LogLevel to Debug at app level
Docs: "Logger vs. sink minimums - it is important to realize that the logging level can only be raised for sinks, not lowered. So, if the logger's MinimumLevel is set to Information then a sink with Debug as its specified level will still only see Information level events. This is because the logger-level configuration controls which logging statements will result in the creation of events, while the sink-level configuration only filters these. To create a single logger with a more verbose level, use a separate LoggerConfiguration"
I don't quite get the idea of using separate LoggerConfigurations. Ability to lower minimum log level by source context would be still useful.
This issue is over a year old, seemingly without a conclusion. I second the opinion of @FLAMESpl that the ability to lower minimum log level by source context would be useful. This was the behavior I expected from reading the documentation I have found - I didn't find the section quoted by @avireddy02.
Any words from contributors on this issue?
Hi! Some background:
MinimumLevel
(and overrides) control which log statements generate LogEvent
sLogEvent
s get throughIn the sample code, minimum level overrides mean that WeatherForecastController
's Verbose
log statements result in log events, but, the filter in front of the sink subsequently discards them.
There's no reason in the sample code to have restrictedToMinimumLevel
on the Console
sink; just removing it will "fix" the issue.
If you're in a different situation and need to use more nuanced minimum level overrides + sink-specific filtering, then WriteTo.Conditional()
is a better alternative to restrictedToMinimumLevel
.
Serilog is designed as an event processing pipeline, so this kind of behavior makes a bit more sense from that angle.
Hope this helps! Closing as by-design, but if the explanation above isn't clear, please let me know below and I'll add more info :-)
hey there I'm trying to enable debug logging for a specific class using serilog and found few examples using MinimumLevel.Override. Unfortunately its not working as intended.
Ex: Sample GitRepo In this example I have configured "Serilog.Ext.Logging.Bug._174.Controllers.WeatherForecastController" to Verbose, LogTrace is not showing up in console
Console Out: [18:28:30 INF] Info 1