コード例 #1
0
        public void UpdateMaxNumberOfLogs(int maxNumberOfLogs)
        {
            if (MaxNumberOfLogsPerLevel <= maxNumberOfLogs)
            {
                MaxNumberOfLogsPerLevel = maxNumberOfLogs;
                return;
            }

            MaxNumberOfLogsPerLevel = maxNumberOfLogs;
            List <LogViewModel> logsToRemove      = new List <LogViewModel>();
            List <LogViewModel> logsToRemoveTrace = LogsTrace.Take(LogsTrace.Count - maxNumberOfLogs).ToList();

            logsToRemoveTrace.ForEach((m) => { LogsTrace.Remove(m); });
            List <LogViewModel> logsToRemoveDebug = LogsDebug.Take(LogsDebug.Count - maxNumberOfLogs).ToList();

            logsToRemoveDebug.ForEach((m) => { LogsDebug.Remove(m); });
            List <LogViewModel> logsToRemoveInfo = LogsInfo.Take(LogsInfo.Count - maxNumberOfLogs).ToList();

            logsToRemoveInfo.ForEach((m) => { LogsInfo.Remove(m); });
            List <LogViewModel> logsToRemoveWarn = LogsWarn.Take(LogsWarn.Count - maxNumberOfLogs).ToList();

            logsToRemoveWarn.ForEach((m) => { LogsWarn.Remove(m); });
            List <LogViewModel> logsToRemoveError = LogsError.Take(LogsError.Count - maxNumberOfLogs).ToList();

            logsToRemoveError.ForEach((m) => { LogsError.Remove(m); });
            List <LogViewModel> logsToRemoveFatal = LogsFatal.Take(LogsFatal.Count - maxNumberOfLogs).ToList();

            logsToRemoveFatal.ForEach((m) => { LogsFatal.Remove(m); });

            logsToRemove.AddRange(logsToRemoveTrace);
            logsToRemove.AddRange(logsToRemoveDebug);
            logsToRemove.AddRange(logsToRemoveInfo);
            logsToRemove.AddRange(logsToRemoveWarn);
            logsToRemove.AddRange(logsToRemoveError);
            logsToRemove.AddRange(logsToRemoveFatal);

            logsToRemove.ForEach((m) => {
                if (IsActive && LoggingLevel.IsLogLevelAboveMin(m.Level, SelectedMinLogLevel) && IsNamespaceActive(m) && IsSearchCriteriaMatch(m))
                {
                    Logs.Remove(m);
                }
            });
        }
コード例 #2
0
        public void AddLog(LogViewModel log)
        {
            LogViewModel logToRemove = null;

            if (log.Level == LoggingLevel.TRACE)
            {
                LogsTrace.Add(log);
                if (LogsTrace.Count > MaxNumberOfLogsPerLevel)
                {
                    var last = LogsTrace.First();
                    LogsTrace.Remove(last);
                    logToRemove = last;
                }
            }
            else if (log.Level == LoggingLevel.DEBUG)
            {
                LogsDebug.Add(log);
                if (LogsDebug.Count > MaxNumberOfLogsPerLevel)
                {
                    var last = LogsDebug.First();
                    LogsDebug.Remove(last);
                    logToRemove = last;
                }
            }
            else if (log.Level == LoggingLevel.INFO)
            {
                LogsInfo.Add(log);
                if (LogsInfo.Count > MaxNumberOfLogsPerLevel)
                {
                    var last = LogsInfo.First();
                    LogsInfo.Remove(last);
                    logToRemove = last;
                }
            }
            else if (log.Level == LoggingLevel.WARN)
            {
                LogsWarn.Add(log);
                if (LogsWarn.Count > MaxNumberOfLogsPerLevel)
                {
                    var last = LogsWarn.First();
                    LogsWarn.Remove(last);
                    logToRemove = last;
                }
            }
            else if (log.Level == LoggingLevel.ERROR)
            {
                LogsError.Add(log);
                if (LogsError.Count > MaxNumberOfLogsPerLevel)
                {
                    var last = LogsError.First();
                    LogsError.Remove(last);
                    logToRemove = last;
                }
            }
            else if (log.Level == LoggingLevel.FATAL)
            {
                LogsFatal.Add(log);
                if (LogsFatal.Count > MaxNumberOfLogsPerLevel)
                {
                    var last = LogsFatal.First();
                    LogsFatal.Remove(last);
                    logToRemove = last;
                }
            }

            if (IsActive && LoggingLevel.IsLogLevelAboveMin(log.Level, SelectedMinLogLevel) && IsNamespaceActive(log) && IsSearchCriteriaMatch(log))
            {
                Logs.Insert(0, log);
                if (logToRemove != null)
                {
                    Logs.Remove(logToRemove);
                }
            }
        }