/// <summary> /// A simple test, to see if the log level is enabled. /// Note: logLevel == LogLevels.None should always return false /// logLevel == LogLevels.None is actually checked in the extension /// </summary> /// <param name="logSource">LogSource</param> /// <param name="logLevel">LogLevels</param> /// <returns>true if there are loggers which will log for the LogSource</returns> private static bool IsLogLevelEnabled(LogSource logSource, LogLevels logLevel) { // "Fail-fast" if (logSource is null || logLevel == LogLevels.None) { return(false); } // Check if there are any loggers // ReSharper disable once LoopCanBeConvertedToQuery foreach (var x in LogSettings.LoggerLookup(logSource)) { if (x.LogLevel != LogLevels.None && x.IsLogLevelEnabled(logLevel, logSource)) { return(true); } } return(false); }
/// <inheritdoc /> public virtual bool IsLogLevelEnabled(LogLevels logLevel, LogSource logSource = null) { return(logLevel != LogLevels.None && logLevel >= LogLevel); }
/// <summary> /// Takes care of de-registering the supplied logger for a LogSource /// </summary> /// <param name="logSource">LogSource for the source</param> /// <param name="logger">ILogger to register</param> public static void DeRegisterLoggerFor(LogSource logSource, ILogger logger) { DeRegisterLoggerFor(logSource.Source, logger); }
/// <summary> /// Takes care of registering the supplied logger for a LogSource /// </summary> /// <param name="logSource">LogSource to register for</param> /// <param name="logger">ILogger to register</param> public static void LogTo(this LogSource logSource, ILogger logger) { RegisterLoggerFor(logSource.Source, logger); }
/// <summary> /// Test if LogLevels.Verbose is enabled /// </summary> /// <returns>true if enabled</returns> public static bool IsVerboseEnabled(this LogSource logSource) { return(IsLogLevelEnabled(logSource, LogLevels.Verbose)); }
/// <summary> /// Test if LogLevels.Warn is enabled /// </summary> /// <returns>true if enabled</returns> public static bool IsWarnEnabled(this LogSource logSource) { return(IsLogLevelEnabled(logSource, LogLevels.Warn)); }
/// <summary> /// Test if LogLevels.Info is enabled /// </summary> /// <returns>true if enabled</returns> public static bool IsInfoEnabled(this LogSource logSource) { return(IsLogLevelEnabled(logSource, LogLevels.Info)); }
/// <summary> /// Test if LogLevels.Fatal is enabled /// </summary> /// <returns>true if enabled</returns> public static bool IsFatalEnabled(this LogSource logSource) { return(IsLogLevelEnabled(logSource, LogLevels.Fatal)); }
/// <summary> /// Test if LogLevels.Error enabled /// </summary> /// <returns>true if enabled</returns> public static bool IsErrorEnabled(this LogSource logSource) { return(IsLogLevelEnabled(logSource, LogLevels.Error)); }
/// <summary> /// Test if LogLevels.Debug is enabled /// </summary> /// <returns>true if enabled</returns> public static bool IsDebugEnabled(this LogSource logSource) { return(IsLogLevelEnabled(logSource, LogLevels.Debug)); }
/// <summary> /// This extension will create LogInfo, for LogLevels.Warn /// </summary> /// <param name="logSource">LogContext is the context (source) from where the log entry came</param> /// <param name="lineNumber">Should be set by the compiler, int lineNumber of the log statement</param> /// <param name="methodName">Should be set by the compiler, is the calling method</param> /// <returns>LogInfo</returns> public static LogInfo Warn(this LogSource logSource, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string methodName = "") { return(CreateLogInfo(logSource, LogLevels.Warn, lineNumber, methodName)); }