Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current Serilog MinimumLevel

Is there a way to get the minimum log level from Serilog's current configuration in a controller or middleware?

like image 929
andre_ss6 Avatar asked Mar 12 '18 00:03

andre_ss6


1 Answers

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()).

like image 71
Nicholas Blumhardt Avatar answered Nov 05 '22 17:11

Nicholas Blumhardt