Inheritance: INotifyPropertyChanged
        private bool IsSearchCriteriaMatch(LogViewModel log)
        {
            try {
                // Default
                if (String.IsNullOrEmpty(SearchCriteria))
                {
                    return(true);
                }

                // Search
                if (!IsSearchCriteriaInverted)
                {
                    if ((!String.IsNullOrEmpty(log.Application) && log.Application.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Namespace) && log.Namespace.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Message) && log.Message.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Exception) && log.Exception.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())))
                    {
                        return(true);
                    }
                    return(false);
                }
                else
                {
                    if ((!String.IsNullOrEmpty(log.Application) && log.Application.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Namespace) && log.Namespace.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Message) && log.Message.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Exception) && log.Exception.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())))
                    {
                        return(false);
                    }
                    return(true);
                }
            }
            catch (Exception e) {
                Console.WriteLine("Invalid search criteria: " + e);
                return(false);
            }
        }
        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);
                }
            }
        }
Beispiel #3
0
 private void SetLogCountByLevel(LogViewModel log, NamespaceViewModel ns)
 {
     ns.Count++;
     if (log.Level == LoggingLevel.TRACE) {
         ns.CountTrace++;
     } else if (log.Level == LoggingLevel.DEBUG) {
         ns.CountDebug++;
     } else if (log.Level == LoggingLevel.INFO) {
         ns.CountInfo++;
     } else if (log.Level == LoggingLevel.WARN) {
         ns.CountWarn++;
     } else if (log.Level == LoggingLevel.ERROR) {
         ns.CountError++;
     } else if (log.Level == LoggingLevel.FATAL) {
         ns.CountFatal++;
     }
 }
Beispiel #4
0
 private void SetNamespaceHighlight(LogViewModel log)
 {
     if (selectedLog != null) {
         SelectedNamespaceViewModel = Namespaces.Flatten(x => x.Children).FirstOrDefault(model => model.Fullname.Equals(selectedLog.Application + Constants.NAMESPACE_SPLITTER + selectedLog.Namespace));
     }
 }
Beispiel #5
0
 private void HandleNamespace(NamespaceViewModel parent, string suffix, ApplicationViewModel application, LogViewModel log)
 {
     // Example: VerbTeX.View (Verbosus was processed before)
     string nsLogFull = suffix;
     // Example: VerbTeX
     string nsLogPart = nsLogFull.Split(new string[] { Constants.NAMESPACE_SPLITTER }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
     // Try to get existing namespace with name VerbTeX
     var nsChild = parent.Children.FirstOrDefault(m => m.Name == nsLogPart);
     if (nsChild == null) {
         nsChild = new NamespaceViewModel(nsLogPart, application);
         nsChild.IsChecked = parent.IsChecked;
         parent.Children.Add(nsChild);
         nsChild.Parent = parent;
     }
     if (suffix.Contains(Constants.NAMESPACE_SPLITTER)) {
         HandleNamespace(nsChild, suffix.Substring(suffix.IndexOf(Constants.NAMESPACE_SPLITTER) + 1), application, log);
     } else {
         SetLogCountByLevel(log, nsChild);
     }
 }
        private bool IsSearchCriteriaMatch(LogViewModel log)
        {
            try {
                // Default
                if (String.IsNullOrEmpty(SearchCriteria)) {
                    return true;
                }

                // Search
                if (!IsSearchCriteriaInverted) {
                    if ((!String.IsNullOrEmpty(log.Application) && log.Application.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Namespace) && log.Namespace.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Message) && log.Message.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Exception) && log.Exception.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant()))) {
                        return true;
                    }
                    return false;
                }
                else {
                    if ((!String.IsNullOrEmpty(log.Application) && log.Application.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Namespace) && log.Namespace.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Message) && log.Message.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant())) ||
                        (!String.IsNullOrEmpty(log.Exception) && log.Exception.ToLowerInvariant().Contains(SearchCriteria.ToLowerInvariant()))) {
                        return false;
                    }
                    return true;
                }
            }
            catch (Exception e) {
                Console.WriteLine("Invalid search criteria: " + e);
                return false;
            }
        }
        private bool IsNamespaceActive(LogViewModel log)
        {
            // Try to get existing root namespace with name of application
            var nsApplication = Namespaces.FirstOrDefault(m => m.Name == log.Application);
            if (nsApplication == null) {
                return false;
            }

            // Example: Verbosus.VerbTeX.View
            string nsLogFull = log.Namespace;
            // Example: Verbosus
            string nsLogPart = nsLogFull.Split(new string[] { Constants.NAMESPACE_SPLITTER }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
            // Try to get existing namespace with name Verbosus
            var ns = nsApplication.Children.FirstOrDefault(m => m.Name == nsLogPart);
            if (ns == null) {
                return false;
            }
            if (nsLogFull.Contains(Constants.NAMESPACE_SPLITTER)) {
                return IsNamespaceActive(ns, nsLogFull.Substring(nsLogFull.IndexOf(Constants.NAMESPACE_SPLITTER) + 1));
            }
            else {
                return ns.IsChecked;
            }
        }
        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 HandleNamespace(NamespaceViewModel parent, string suffix, ApplicationViewModel application, LogViewModel log)
        {
            // Example: VerbTeX.View (Verbosus was processed before)
            string nsLogFull = suffix;
            // Example: VerbTeX
            string nsLogPart = nsLogFull.Split(new string[] { Constants.NAMESPACE_SPLITTER }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
            // Try to get existing namespace with name VerbTeX
            var nsChild = parent.Children.FirstOrDefault(m => m.Name == nsLogPart);

            if (nsChild == null)
            {
                nsChild           = new NamespaceViewModel(nsLogPart, application);
                nsChild.IsChecked = parent.IsChecked;
                parent.Children.Add(nsChild);
                nsChild.Parent = parent;
            }
            if (suffix.Contains(Constants.NAMESPACE_SPLITTER))
            {
                HandleNamespace(nsChild, suffix.Substring(suffix.IndexOf(Constants.NAMESPACE_SPLITTER) + 1), application, log);
            }
            else
            {
                SetLogCountByLevel(log, nsChild);
            }
        }