public static void Main() { var baseEntry = new SimpleLogEntry() { Created = DateTime.Now, Message = "test" }; var simpleEntry = new SimpleLogEntry(baseEntry) { AdditionalInfo = "additional" }; var exceptionEntry = new ExceptionLogEntry(baseEntry) { ExceptionCode = 111 }; //it is possible to declare multiple visitors for particular hierarchy of objects // for example: PersistentLogEntryVisitors that allows to process LogEntries and save them to storage var visitor = new LogEntryVisitor(); visitor.ProcessLogEntry(simpleEntry); Assert.Contains("simple", visitor.State); visitor.ProcessLogEntry(exceptionEntry); Assert.Contains("exception", visitor.State); TestRunner.Print(); }
public void CompositeTests() { var rule = LogRuleFactory.RejectOldEntriesWithLowSeverity(TimeSpan.FromDays(7)); LogEntry logEntry = new ExceptionLogEntry(); Assert.IsTrue(rule.ShouldImport(logEntry)); }
public void ImportsExceptionEntry() { // Arrange var logEntry = new ExceptionLogEntry(); // Assert Assert.IsTrue(_rule.ShouldImport(logEntry)); }
static void Main(string[] args) { ExceptionLogEntry exlogEntry = new ExceptionLogEntry(); SimpleLogEntry simpleLogEntry = new SimpleLogEntry(); var dbsaver = new DatabaseLogSaver(); dbsaver.SaveLogEntry(simpleLogEntry); dbsaver.SaveLogEntry(exlogEntry); Console.ReadLine(); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { ILogEntry document; if (exception == null) { document = new LogEntry() { EventId = eventId, MachineName = Environment.MachineName, Category = this.Category, LogLevel = logLevel, CreatedDateTime = DateTime.UtcNow, Message = formatter(state, exception) }; } else { var formattedException = new StringBuilder(); formattedException.Append(state); formattedException.AppendLine(string.Format("\n[{0}] {1}", exception.GetType().Name, exception.Message)); formattedException.AppendLine(exception.StackTrace); var innerException = exception.InnerException; while (innerException != null) { formattedException.AppendLine(string.Format("\n[{0}] {1}", innerException.GetType().Name, innerException.Message)); innerException = innerException.InnerException; } document = new ExceptionLogEntry() { EventId = eventId, MachineName = Environment.MachineName, Category = this.Category, LogLevel = logLevel, CreatedDateTime = DateTime.UtcNow, Message = formatter(state, exception), Exception = formattedException.ToString() }; } this.DatabaseWriter.Write(document); }
void ILogEntryVisitor.Visit(ExceptionLogEntry exceptionLogEntry) { State = $"LogEntryVisitor[{nameof(exceptionLogEntry)}]"; }
public void SaveException(ExceptionLogEntry exceptionLogEntry) { Console.WriteLine("ElasticSearchLogSaver SaveException() " + exceptionLogEntry.Exception.Message); }
void ILogEntryVisitor.Visit(ExceptionLogEntry exceptionLogEntry) { SaveException(exceptionLogEntry); }
private void SaveException(ExceptionLogEntry exceptionLogEntry) { }
private void SaveException(ExceptionLogEntry logEntry) { }
public void SaveException(ExceptionLogEntry exceptionLogEntry) { // saves to es }
private void SaveException(ExceptionLogEntry exceptionLogEntry) { Console.WriteLine("ExLog saved"); }
private void SaveException(ExceptionLogEntry exception) { throw new System.NotImplementedException(); }
public void Visit(ExceptionLogEntry exceptionLogEntry) { SaveException(exceptionLogEntry); }
public void Insert(ExceptionLogEntry entry) { _context.ExceptionLogEntries.Add(entry); _context.SaveChanges(); }