public void logging_trace_listener_test()
        {
            var adapter = new CapturingLoggerAdapter();

            LogManager.Adapter = adapter;

            var listener = new LoggingTraceListener();

            listener.DefaultTraceEventType = (TraceEventType)0xFFFF;

            AssertExpectedLogLevel(listener, TraceEventType.Start, LogLevelType.Trace);
            AssertExpectedLogLevel(listener, TraceEventType.Stop, LogLevelType.Trace);
            AssertExpectedLogLevel(listener, TraceEventType.Suspend, LogLevelType.Trace);
            AssertExpectedLogLevel(listener, TraceEventType.Resume, LogLevelType.Trace);
            AssertExpectedLogLevel(listener, TraceEventType.Transfer, LogLevelType.Trace);
            AssertExpectedLogLevel(listener, TraceEventType.Verbose, LogLevelType.Debug);
            AssertExpectedLogLevel(listener, TraceEventType.Information, LogLevelType.Info);
            AssertExpectedLogLevel(listener, TraceEventType.Warning, LogLevelType.Warn);
            AssertExpectedLogLevel(listener, TraceEventType.Error, LogLevelType.Error);
            AssertExpectedLogLevel(listener, TraceEventType.Critical, LogLevelType.Fatal);

            adapter.Clear();
            listener.DefaultTraceEventType = TraceEventType.Warning;
            listener.Write("some message", "some category");
            var logName = adapter.LastEvent.Source.ArgumentEntity.LogName;

            logName.Should().Be(string.Format("{0}.{1}", listener.Name, "some category"));
            adapter.LastEvent.Level.Should().Be(LogLevelType.Warn);
            adapter.LastEvent.RenderedMessage.Should().Be("some message");
            adapter.LastEvent.Exception.Should().BeNull();
        }
예제 #2
0
        public void logging_adapter_clear_events_test()
        {
            var adapter    = new CapturingLoggerAdapter();
            var testLogger = (CapturingLogger)adapter.GetLogger("test");

            testLogger.Trace("message1");
            testLogger.Trace("message2");
            adapter.LastEvent.Should().NotBeNull();
            adapter.LoggerEvents.Count.Should().Be(2);

            adapter.Clear();
            adapter.LastEvent.Should().BeNull();
            adapter.LoggerEvents.Count.Should().Be(0);
        }
예제 #3
0
        public void logging_can_change_log_level_test()
        {
            var adapter    = new CapturingLoggerAdapter();
            var testLogger = (CapturingLogger)adapter.GetLogger("test");

            testLogger.ArgumentEntity.Level.Should().Be(LogLevelType.All);

            testLogger.Trace("message1");
            testLogger.LoggerEvents.Count.Should().Be(1);

            testLogger.ArgumentEntity.Level = LogLevelType.Debug;
            testLogger.Trace("message2");
            testLogger.LastEvent.MessageObject.Should().Be("message1");
        }
        public void logging_not_log_below_filter_level_test()
        {
            var adapter = new CapturingLoggerAdapter();

            LogManager.Adapter = adapter;

            var listener = new LoggingTraceListener();

            listener.Filter = new EventTypeFilter(SourceLevels.Warning);
            adapter.Clear();
            listener.TraceEvent(null, "sourceName", TraceEventType.Information, -1, "format {0}", "Information");
            adapter.LastEvent.Should().BeNull();

            AssertExpectedLogLevel(listener, TraceEventType.Warning, LogLevelType.Warn);
            AssertExpectedLogLevel(listener, TraceEventType.Error, LogLevelType.Error);
        }
예제 #5
0
        public void logging_captures_individual_events_test()
        {
            var adapter    = new CapturingLoggerAdapter();
            var testLogger = (CapturingLogger)adapter.GetLogger("test");

            testLogger.Trace("message1");
            testLogger.Trace("message2");

            testLogger.LoggerEvents.Count.Should().Be(2);
            testLogger.LastEvent.MessageObject.Should().Be("message2");
            testLogger.LoggerEvents[0].MessageObject.Should().Be("message1");
            testLogger.LoggerEvents[1].MessageObject.Should().Be("message2");

            testLogger.Clear();
            testLogger.LastEvent.Should().BeNull();
            testLogger.LoggerEvents.Count.Should().Be(0);
        }
        public void logging_trace_listener_null_category_test()
        {
            var adapter = new CapturingLoggerAdapter();

            LogManager.Adapter = adapter;
            var listener = new LoggingTraceListener();

            listener.DefaultTraceEventType = TraceEventType.Warning;
            listener.Write("some message", null);

            var logName    = adapter.LastEvent.Source.ArgumentEntity.LogName;
            var exceptName = string.Format("{0}.{1}", listener.Name, "");

            logName.Should().Be(exceptName);
            adapter.LastEvent.Level.Should().Be(LogLevelType.Warn);
            adapter.LastEvent.RenderedMessage.Should().Be("some message");
            adapter.LastEvent.Exception.Should().BeNull();
        }
예제 #7
0
        public void logging_adapter_captures_all_events_test()
        {
            var adapter     = new CapturingLoggerAdapter();
            var testLogger  = (CapturingLogger)adapter.GetLogger("test");
            var test2Logger = (CapturingLogger)adapter.GetLogger("test2");

            testLogger.Trace("message1");
            test2Logger.Trace("message2");

            testLogger.LoggerEvents.Count.Should().Be(1);
            testLogger.LastEvent.MessageObject.Should().Be("message1");
            test2Logger.LoggerEvents.Count.Should().Be(1);
            test2Logger.LastEvent.MessageObject.Should().Be("message2");

            adapter.LoggerEvents.Count.Should().Be(2);
            adapter.LoggerEvents[0].MessageObject.Should().Be("message1");
            test2Logger.LoggerEvents.Count.Should().Be(1);
            adapter.LoggerEvents[1].MessageObject.Should().Be("message2");
        }
예제 #8
0
 public CapturingLogger(CapturingLoggerAdapter owner, string logName)
     : base(InitLogArgumentEntity(logName))
 {
     GuardHelper.ArgumentNotNull(() => owner);
     Owner = owner;
 }