private void CloseAppender() { if (appender != null) { (log.Logger as log4net.Core.IAppenderAttachable).RemoveAppender(appender); appender.Close(); appender = null; } }
private static IEnumerable <string> GetAllRenderedMessages(Action action) { var memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(memoryAppender); LogHelper.SetLoggingLevel(Level.All); action(); var renderedMessages = memoryAppender.GetEvents().Select(le => le.RenderedMessage).ToList(); memoryAppender.Close(); LogHelper.ResetLogging(); return(renderedMessages); }
public static void AssertLogMessageIsGenerated(Action action, string message) { var memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(memoryAppender); LogHelper.SetLoggingLevel(Level.All); action(); IEnumerable <string> renderedMessages = memoryAppender.GetEvents().Select(le => le.RenderedMessage).ToList(); if (!renderedMessages.Any(s => s == message)) { Assert.Fail(String.Format("Message \"{0}\" not found in messages of log4net", message)); } memoryAppender.Close(); LogHelper.ResetLogging(); }
private static IEnumerable <Tuple <string, Level, Exception> > GetAllRenderedMessagesWithExceptions(Action action) { var memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(memoryAppender); LogHelper.SetLoggingLevel(Level.All); action(); List <Tuple <string, Level, Exception> > renderedMessages = memoryAppender.GetEvents() .Select(le => Tuple.Create(le.RenderedMessage, le.Level, le.ExceptionObject)) .ToList(); memoryAppender.Close(); LogHelper.ResetLogging(); return(renderedMessages); }
public void Dispose() { ((Logger)_logger.Logger).RemoveAllAppenders(); _appender.Close(); LogManager.ShutdownRepository(repositoryName); }