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>()); }
private void UpdateByActiveChange(bool oldIsActive, bool newIsActive) { if (oldIsActive == newIsActive) { return; } if (newIsActive) { var levels = GetLogsByLevel(SelectedMinLogLevel); levels.ForEach((m) => { if (IsNamespaceActive(m) && IsSearchCriteriaMatch(m)) { Logs.AddOrdered(m); } }); } else { LogsTrace.ForEach((m) => { Logs.Remove(m); }); LogsDebug.ForEach((m) => { Logs.Remove(m); }); LogsInfo.ForEach((m) => { Logs.Remove(m); }); LogsWarn.ForEach((m) => { Logs.Remove(m); }); LogsError.ForEach((m) => { Logs.Remove(m); }); LogsFatal.ForEach((m) => { Logs.Remove(m); }); } }
private void logsBtn_Click(object sender, EventArgs e) { if (mainPanel.Controls.ContainsKey("LogsInfo")) { mainPanel.Controls.Remove(logs); } logs = new LogsInfo(); mainPanel.Controls.Add(logs); logs.BringToFront(); logs.Visible = true; }
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); } }); }
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); } } }
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); } }); } } } }