IsEnabled won't actually work, even if you wrote a function and ran through each level looking for when the result changed from true to false. Based on this answer and looking at the source code here:
This is ConsoleLogger
public bool IsEnabled(LogLevel logLevel)
{
return logLevel != LogLevel.None;
}
This is DebugLogger
public bool IsEnabled(LogLevel logLevel)
{
// Everything is enabled unless the debugger is not attached
return Debugger.IsAttached && logLevel != LogLevel.None;
}
and this is EventLogLogger
public bool IsEnabled(LogLevel logLevel)
{
return logLevel != LogLevel.None &&
(_settings.Filter == null || _settings.Filter(_name, logLevel));
}
So checking IsEnabled may tell you various things about their configuration, such as whether EventLogLogger is being filtered or not, but it's not going to tell you what the minimum loglevel is. I think to do that, you are going to have to get the data from the configuration system directly yourself (set up your own "loggingOptions" class, use config.bind or get, etc.) And even that isn't going to help if you happen to have something weird like "WarningLogAndAboveLogger" registered that ignores the config and hard-codes it's own default. And even when parsing config does work, you'd have to make sure you compare categories and handle all of the heirarchy and such, since ConsoleLogger with one category can have a different minimum level than ConsoleLogger with some other category.
IsEnable
method is much faster than anyLog
-method that you call. But if you don't want to check it every time before logging, I may suggest you to calculate minimum log level on application startup and inject it using custom interface like 'ILogLevelProvider' which returns your calculated value. If you have a problem with implementing caclulation of min-log-level, let me know – XerophyteEnum.GetValues(typeof(LogLevel)).Cast<LogLevel>().FirstOrDefault(level => logger.IsEnabled(level))
. This should return the log level for you. – Squally