public override string Export(LogLine.LogType[] logTypes) { var sb = new StringBuilder(); var mainStatus = GetMainStatus(); if (!String.IsNullOrEmpty(mainStatus)) { sb.AppendLine(mainStatus + "\r\n"); } var countersStatus = GetCountersStatus(); if (!String.IsNullOrEmpty(countersStatus)) { sb.AppendLine(countersStatus + "\r\n"); } var logLines = GetLogLines(logTypes); if (!String.IsNullOrEmpty(logLines)) { sb.AppendLine(logLines + "\r\n"); } return sb.ToString(); }
protected virtual void ProcessLevelLoggerAndChildren(LevelLogger levelLogger, LogLine.LogType[] logTypes, ref StringBuilder sb, int level) { var children = levelLogger.GetChildren(); if (children != null) { var prefix = GetPrefixIndent(level); foreach (var child in children) { var logLine = child as LogLine; if (logLine != null) { if (logTypes == null || logTypes.Contains(logLine.Type)) { sb.AppendLine(String.Format("{0} {1}", prefix, OutputLogLine(logLine))); continue; } } var childLevelLogger = child as LevelLogger; if (childLevelLogger != null) { if (childLevelLogger.HasErrorsOrInfos()) { var keys = childLevelLogger.HasKeys() ? GetKeys(childLevelLogger) : ""; var name = GetCategoryName(childLevelLogger); if (!String.IsNullOrEmpty(name)) { sb.AppendLine(String.Format("{0} {1} {2}", prefix, name, keys)); } ProcessLevelLoggerAndChildren(childLevelLogger, logTypes, ref sb, level + 1); } } } } }
protected virtual string OutputLogLine(LogLine logLine) { if (logLine != null) { return String.Format("{0} - {1} - {2}", logLine.Category, logLine.Message, logLine.TimeStamp); } return String.Empty; }
public override string GetLogLines(LogLine.LogType[] logTypes) { var sb = new StringBuilder(); if (Logger != null) { var startText = Logger.HasKeys() ? "Import job:\r\n" + GetKeys(Logger) + "\r\n" : "Import job:\r\n"; sb.AppendLine(startText); //sb.AppendLine(String.Format("{0}", GetTimeAndTimeSpanInfo())); if (Logger.HasFatalsErrorsOrInfos()) { sb.AppendLine(String.Format("Log:")); var logger = Logger as Builder.Logger; if (logger != null) { OutputGroupedCategories(logger, logTypes, ref sb); } ProcessLevelLoggerAndChildren(Logger, logTypes, ref sb, 0); } else { sb.AppendLine( String.Format( "The job was processed, with no errors or infos.", startText)); } } return sb.ToString(); }
protected virtual void OutputGroupedCategories(Builder.Logger logger, LogLine.LogType[] logTypes, ref StringBuilder sb) { var fatalSb = new StringBuilder(); var errorSb = new StringBuilder(); var infoSb = new StringBuilder(); foreach (var categoryLogLines in logger.LogLineByCategory) { var currentSb = infoSb; var category = categoryLogLines.Key; var loglineList = categoryLogLines.Value; if (loglineList != null && loglineList.Any()) { int totalLines = loglineList.Count; var firstLogLine = loglineList.FirstOrDefault(); if (firstLogLine != null) { if (firstLogLine.Type == LogLine.LogType.Fatal && (logTypes == null || logTypes.Contains(firstLogLine.Type))) { currentSb = fatalSb; } else if (firstLogLine.Type == LogLine.LogType.Error && (logTypes == null || logTypes.Contains(firstLogLine.Type))) { currentSb = errorSb; } else if (firstLogLine.Type == LogLine.LogType.Info && (logTypes == null || logTypes.Contains(firstLogLine.Type))) { currentSb = infoSb; } else { continue; } } currentSb.AppendLine(String.Format("* {0} ({1}) ", category, totalLines)); foreach (var logLine in loglineList) { if (logTypes == null || logTypes.Contains(logLine.Type)) { currentSb.AppendLine(String.Format("** {0}", OutputLogLine(logLine))); } } } } var fatal = fatalSb.ToString(); var error = errorSb.ToString(); var info = infoSb.ToString(); if (!String.IsNullOrEmpty(fatal)) { sb.AppendLine("Fatals by type:"); sb.AppendLine(fatal + "\r\n\r\n"); } if (!String.IsNullOrEmpty(error)) { sb.AppendLine("Errors by type:"); sb.AppendLine(error + "\r\n\r\n"); } if (!String.IsNullOrEmpty(info)) { sb.AppendLine("Info by type:"); sb.AppendLine(info + "\r\n\r\n"); } }
public virtual void AddInfo(string key, string message) { var logLine = new LogLine(key, message, LogLine.LogType.Info); AddToLogLines(logLine); }
protected override void ChildAddedLogLine(object sender, LogLine logLine) { base.ChildAddedLogLine(sender, logLine); if (logLine != null) { var category = logLine.Category; if (LogLineByCategory != null) { if (LogLineByCategory.ContainsKey(category)) { var logLineList = LogLineByCategory[category]; if (logLineList != null) { logLineList.Add(logLine); } else { logLineList = new List<LogLine> {logLine}; } LogLineByCategory[category] = logLineList; } else { LogLineByCategory.Add(category, new List<LogLine> {logLine}); } } } }
private void UpdateInfosAndErrorAdded(LogLine logLine) { if (!IsInfosAdded && logLine.Type == LogLine.LogType.Info) { IsInfosAdded = true; } if (!IsErrorsAdded && logLine.Type == LogLine.LogType.Error) { IsErrorsAdded = true; } if (!IsFatalsAdded && logLine.Type == LogLine.LogType.Fatal) { IsFatalsAdded = true; } }
private void AddToLogLines(LogLine logLine) { UpdateInfosAndErrorAdded(logLine); if (AddedLogLine != null) { AddedLogLine(this, logLine); } if (Children == null) { Children = new ArrayList(); } Children.Add(logLine); }
protected virtual void ChildAddedLogLine(object sender, LogLine logLine) { UpdateInfosAndErrorAdded(logLine); if (AddedLogLine != null) { AddedLogLine(sender, logLine); } }
public abstract string GetLogLines(LogLine.LogType[] logTypes);
public abstract string Export(LogLine.LogType[] logTypes);