public static string GetText(this LogEntryBase logEntry) { var sb = new StringBuilder(); sb.AppendFormat("[{0}] ", logEntry.EntryDateTime) .AppendLine(logEntry.Message) .AppendLine(logEntry.AdditionalInformation); return(sb.ToString()); }
public void SaveLogEntry(LogEntryBase logEntry) { var exception = logEntry as ExceptionLogEntry; if (exception != null) { SaveException(exception); } else { var simpleLogEntry = logEntry as SimpleLogEntry; if (simpleLogEntry != null) { SaveSimpleLogEntry(simpleLogEntry); } } }
// functional version of visitor pattern public static void Match(this LogEntryBase logEntryBase, Action<ExceptionLogEntry> exceptionLogEntryMatch, Action<SimpleLogEntry> simpleLogEntryMatch) { var exceptionLogEntry = logEntryBase as ExceptionLogEntry; if (exceptionLogEntry != null) { exceptionLogEntryMatch(exceptionLogEntry); return; } var simpleLogEntry = logEntryBase as SimpleLogEntry; if (simpleLogEntry != null) { simpleLogEntryMatch(simpleLogEntry); return; } throw new InvalidOperationException("Unknown LogEntry type"); }
public void SaveLogEntry(LogEntryBase logEntry) { logEntry.Accept(this); }
public void SaveLogEntry(LogEntryBase logEntry) { logEntry.Match(SaveException, SaveSimpleLogEntry); }