Exemple #1
0
        public static bool IsLogLevelAboveMin(LoggingLevel level, LoggingLevel minLevel)
        {
            if (level == null || minLevel == null) {
                return false;
            }

            if (minLevel == TRACE) {
                return true;
            }
            if (minLevel == DEBUG && (level == DEBUG || level == INFO || level == WARN || level == ERROR || level == FATAL)) {
                return true;
            }
            if (minLevel == INFO && (level == INFO || level == WARN || level == ERROR || level == FATAL)) {
                return true;
            }
            if (minLevel == WARN && (level == WARN || level == ERROR || level == FATAL)) {
                return true;
            }
            if (minLevel == ERROR && (level == ERROR || level == FATAL)) {
                return true;
            }
            if (minLevel == FATAL && (level == FATAL)) {
                return true;
            }
            return false;
        }
Exemple #2
0
        /// <summary>
        /// Gets the log level incl. the toLevel if fromLevel != toLevel
        /// Example (remove): fromLevel = Debug, toLevel = Warn -> return = Debug, Info
        /// Example (add): fromLevel = Warn, toLevel = Debug -> return = Info, Debug
        /// </summary>
        public static LoggingLevel[] GetLogLevelsBetween(LoggingLevel fromLevel, LoggingLevel toLevel)
        {
            if (fromLevel == toLevel || fromLevel == null || toLevel == null) {
                return new LoggingLevel[] { };
            }

            IEnumerable<LoggingLevel> levelsBetween;
            if (fromLevel.Id < toLevel.Id) {
                levelsBetween = Levels.Where(m => m.Id >= fromLevel.Id && m.Id < toLevel.Id);
            } else {
                levelsBetween = Levels.Where(m => m.Id >= toLevel.Id && m.Id < fromLevel.Id);
            }

            return levelsBetween.ToArray();
        }
Exemple #3
0
        /// <summary>
        /// Gets the log level incl. the toLevel if fromLevel != toLevel
        /// Example (remove): fromLevel = Debug, toLevel = Warn -> return = Debug, Info
        /// Example (add): fromLevel = Warn, toLevel = Debug -> return = Info, Debug
        /// </summary>
        public static LoggingLevel[] GetLogLevelsBetween(LoggingLevel fromLevel, LoggingLevel toLevel)
        {
            if (fromLevel == toLevel || fromLevel == null || toLevel == null)
            {
                return(new LoggingLevel[] { });
            }

            IEnumerable <LoggingLevel> levelsBetween;

            if (fromLevel.Id < toLevel.Id)
            {
                levelsBetween = Levels.Where(m => m.Id >= fromLevel.Id && m.Id < toLevel.Id);
            }
            else
            {
                levelsBetween = Levels.Where(m => m.Id >= toLevel.Id && m.Id < fromLevel.Id);
            }

            return(levelsBetween.ToArray());
        }
 private void UpdateByLogLevelChange(LoggingLevel oldLogLevel, LoggingLevel newLogLevel)
 {
     if (!IsActive) {
         return;
     }
     if (oldLogLevel == null || newLogLevel == null || oldLogLevel.Id == newLogLevel.Id) {
         return;
     }
     bool isAdd = oldLogLevel.Id > newLogLevel.Id;
     var levelsBetween = LoggingLevel.GetLogLevelsBetween(oldLogLevel, newLogLevel);
     foreach (var levelBetween in levelsBetween) {
         if (levelBetween == LoggingLevel.TRACE) {
             if (isAdd) {
                 LogsTrace.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.AddOrdered(m); });
             } else {
                 LogsTrace.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.Remove(m); });
             }
         } else if (levelBetween == LoggingLevel.DEBUG) {
             if (isAdd) {
                 LogsDebug.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.AddOrdered(m); });
             } else {
                 LogsDebug.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.Remove(m); });
             }
         } else if (levelBetween == LoggingLevel.INFO) {
             if (isAdd) {
                 LogsInfo.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.AddOrdered(m); });
             } else {
                 LogsInfo.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.Remove(m); });
             }
         } else if (levelBetween == LoggingLevel.WARN) {
             if (isAdd) {
                 LogsWarn.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.AddOrdered(m); });
             } else {
                 LogsWarn.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.Remove(m); });
             }
         } else if (levelBetween == LoggingLevel.ERROR) {
             if (isAdd) {
                 LogsError.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.AddOrdered(m); });
             } else {
                 LogsError.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.Remove(m); });
             }
         } else if (levelBetween == LoggingLevel.FATAL) {
             if (isAdd) {
                 LogsFatal.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.AddOrdered(m); });
             } else {
                 LogsFatal.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) Logs.Remove(m); });
             }
         }
     }
 }
 private List<LogViewModel> GetLogsByLevel(LoggingLevel level)
 {
     if (level == LoggingLevel.TRACE) {
         return LogsTrace.Union(LogsDebug).Union(LogsInfo).Union(LogsWarn).Union(LogsError).Union(LogsFatal).ToList();
     }
     else if (level == LoggingLevel.DEBUG) {
         return LogsDebug.Union(LogsInfo).Union(LogsWarn).Union(LogsError).Union(LogsFatal).ToList();
     }
     else if (level == LoggingLevel.INFO) {
         return LogsInfo.Union(LogsWarn).Union(LogsError).Union(LogsFatal).ToList();
     }
     else if (level == LoggingLevel.WARN) {
         return LogsWarn.Union(LogsError).Union(LogsFatal).ToList();
     }
     else if (level == LoggingLevel.ERROR) {
         return LogsError.Union(LogsFatal).ToList();
     }
     else if (level == LoggingLevel.FATAL) {
         return LogsFatal.ToList();
     }
     return new List<LogViewModel>();
 }