コード例 #1
0
        public void Scoped_Loglevel_should_be_honored()
        {
            var firstStringWriter = new StringWriter();
            var loggerFactory     = LogManager.Use <TestingLoggerFactory>();

            using (loggerFactory.BeginScope(firstStringWriter, LogLevel.Warn))
            {
                var firstInstance = new SomeClassThatUsesStaticLogger();
                firstInstance.DoSomething();
            }

            var secondStringWriter = new StringWriter();

            using (loggerFactory.BeginScope(secondStringWriter))
            {
                var secondInstance = new SomeClassThatUsesStaticLogger();
                secondInstance.DoSomething();
            }

            var firstLogString  = firstStringWriter.ToString();
            var secondLogString = secondStringWriter.ToString();

            Assert.AreNotEqual(firstLogString, secondLogString);
            Assert.IsEmpty(firstLogString);
            StringAssert.Contains("NServiceBus.Testing.Tests.Logging.LoggingTests+SomeClassThatUsesStaticLogger 1", secondLogString);
        }
コード例 #2
0
        public void Global_Writer_should_be_honored()
        {
            var loggerFactory = LogManager.Use <TestingLoggerFactory>();
            var globalWriter  = new StringWriter();

            loggerFactory.WriteTo(globalWriter);

            var firstInstance = new SomeClassThatUsesStaticLogger();

            firstInstance.DoSomething();

            var secondStringWriter = new StringWriter();

            using (loggerFactory.BeginScope(secondStringWriter))
            {
                var secondInstance = new SomeClassThatUsesStaticLogger();
                secondInstance.DoSomething();
            }

            var globalLogString = globalWriter.ToString();
            var scopedLogString = secondStringWriter.ToString();

            Assert.AreNotEqual(globalLogString, scopedLogString);
            StringAssert.Contains("NServiceBus.Testing.Tests.Logging.LoggingTests+SomeClassThatUsesStaticLogger 0", globalLogString);
            StringAssert.DoesNotContain("NServiceBus.Testing.Tests.Logging.LoggingTests+SomeClassThatUsesStaticLogger 1", globalLogString);
            StringAssert.Contains("NServiceBus.Testing.Tests.Logging.LoggingTests+SomeClassThatUsesStaticLogger 1", scopedLogString);
            StringAssert.DoesNotContain("NServiceBus.Testing.Tests.Logging.LoggingTests+SomeClassThatUsesStaticLogger 0", scopedLogString);
        }
コード例 #3
0
        public void NoScope_does_work()
        {
            LogManager.Use <TestingLoggerFactory>();

            var secondInstance = new SomeClassThatUsesStaticLogger();

            secondInstance.DoSomething();
        }