Is there a way to get the minimum log level from Serilog's current configuration in a controller or middleware?
Though it is slightly indirect, you can use IsEnabled
to check this level by level:
Log.IsEnabled(LogEventLevel.Debug)
This is usually enough for these kinds of scenarios. If you really need the precise minimum level, you can try the various LogEventLevel
members individually to figure it out. IsEnabled()
is very fast, so checking a few levels this way won't show up on your performance radar.
Keep in mind that the minimum level can still be overridden per source context (i.e. with MinimumLevel.Override()
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With