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); }
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); }
public void NoScope_does_work() { LogManager.Use <TestingLoggerFactory>(); var secondInstance = new SomeClassThatUsesStaticLogger(); secondInstance.DoSomething(); }