コード例 #1
0
        /// <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);
        }
コード例 #2
0
 /// <inheritdoc />
 public virtual bool IsLogLevelEnabled(LogLevels logLevel, LogSource logSource = null)
 {
     return(logLevel != LogLevels.None && logLevel >= LogLevel);
 }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
 /// <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));
 }
コード例 #6
0
 /// <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));
 }
コード例 #7
0
 /// <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));
 }
コード例 #8
0
 /// <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));
 }
コード例 #9
0
 /// <summary>
 ///     Test if LogLevels.Error enabled
 /// </summary>
 /// <returns>true if enabled</returns>
 public static bool IsErrorEnabled(this LogSource logSource)
 {
     return(IsLogLevelEnabled(logSource, LogLevels.Error));
 }
コード例 #10
0
 /// <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));
 }
コード例 #11
0
 /// <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));
 }