예제 #1
0
 private void CloseAppender()
 {
     if (appender != null)
     {
         (log.Logger as log4net.Core.IAppenderAttachable).RemoveAppender(appender);
         appender.Close();
         appender = null;
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        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();
        }
예제 #4
0
        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);
        }
예제 #5
0
 public void Dispose()
 {
     ((Logger)_logger.Logger).RemoveAllAppenders();
     _appender.Close();
     LogManager.ShutdownRepository(repositoryName);
 }