public void InternalLogger_InternalLoggerDoNotWriteToTraceListenersIfDisabled() { LogConfiguration configuration = new LogConfiguration(); // Redirect the output from the console to a string writer. using (StringTraceListenerScope scope = new StringTraceListenerScope()) { // Write something to the internal log and make sure we did not intercept it. configuration.InternalLogger.Write(LogLevel.Information, "Hello World"); Assert.AreEqual(0, scope.Listener.Messages.Count); } }
public void InternalLogger_InternalLoggerWritesToTraceListeners() { LogConfiguration configuration = new LogConfiguration(); configuration.InternalLogger.Enabled = true; // Redirect the output from the console to a string writer. using (StringTraceListenerScope scope = new StringTraceListenerScope()) { // Write something to the internal log and make sure we intercepted it. configuration.InternalLogger.Write(LogLevel.Information, "Hello World"); Assert.AreEqual(1, scope.Listener.Messages.Count); Assert.AreEqual("[BLACKBOX] Hello World", scope.Listener.Messages[0]); } }
public void LogSinkProxy_UnhandledExceptionsInLogSinkProxyAreHandledAndWrittenToInternalLogWhenWritingMoreThanOneMessage_LogSinkGotNoName() { // This test is using the buffer proxy to buffer up messages and // indirectly use the LogSink.Write(ILogEntry[]) overload on the sink. LogConfiguration configuration = new LogConfiguration(); configuration.InternalLogger.Enabled = true; BufferProxy funnelProxy = new BufferProxy() { BufferSize = 0 }; funnelProxy.Sinks.Add(new ThrowSink(() => new InvalidOperationException("Hello World!"))); configuration.Sinks.Add(funnelProxy); LogKernel kernel = new LogKernel(configuration); ILogger logger = kernel.GetLogger(); string expected = "[BLACKBOX] An unnamed sink of type 'BlackBox.UnitTests.Tests.LogSinkTests+ThrowSink' threw an exception. Hello World!"; using (StringTraceListenerScope scope = new StringTraceListenerScope()) { logger.Write(LogLevel.Information, "TestMessage"); Assert.AreEqual(expected, scope.Listener.Messages[0]); } }
public void InternalLogger_InternalLoggerRespectsThresholdLevel() { LogConfiguration configuration = new LogConfiguration(); configuration.InternalLogger.Enabled = true; configuration.InternalLogger.Threshold = LogLevel.Information; // Redirect the output from the console to a string writer. using (StringTraceListenerScope scope = new StringTraceListenerScope()) { configuration.InternalLogger.Write(LogLevel.Verbose, "1"); Assert.AreEqual(0, scope.Listener.Messages.Count); configuration.InternalLogger.Write(LogLevel.Debug, "2"); Assert.AreEqual(0, scope.Listener.Messages.Count); configuration.InternalLogger.Write(LogLevel.Information, "3"); Assert.AreEqual(1, scope.Listener.Messages.Count); configuration.InternalLogger.Write(LogLevel.Warning, "4"); Assert.AreEqual(2, scope.Listener.Messages.Count); configuration.InternalLogger.Write(LogLevel.Error, "5"); Assert.AreEqual(3, scope.Listener.Messages.Count); configuration.InternalLogger.Write(LogLevel.Fatal, "6"); Assert.AreEqual(4, scope.Listener.Messages.Count); } }
public void LogSink_LogSinkCanWriteToInternalLogger() { LogConfiguration configuration = new LogConfiguration(); configuration.InternalLogger.Enabled = true; configuration.Sinks.Add(new TestSink()); LogKernel kernel = new LogKernel(configuration); ILogger logger = kernel.GetLogger(); using (StringTraceListenerScope scope = new StringTraceListenerScope()) { Assert.AreEqual(0, scope.Listener.Messages.Count); logger.Write(LogLevel.Information, "TestMessage"); Assert.AreEqual(1, scope.Listener.Messages.Count); Assert.AreEqual("TestMessage", scope.Listener.Messages[0]); } }
public void LogSink_UnhandledExceptionsInLogSinkAreHandledAndWrittenToInternalLog_LogSinkGotNoName() { LogConfiguration configuration = new LogConfiguration(); configuration.InternalLogger.Enabled = true; configuration.Sinks.Add(new ThrowSink(() => new InvalidOperationException("Hello World!"))); LogKernel kernel = new LogKernel(configuration); ILogger logger = kernel.GetLogger(); string expected = "[BLACKBOX] An unnamed sink of type 'BlackBox.UnitTests.Tests.LogSinkTests+ThrowSink' threw an exception. Hello World!"; using (StringTraceListenerScope scope = new StringTraceListenerScope()) { logger.Write(LogLevel.Information, "TestMessage"); Assert.AreEqual(expected, scope.Listener.Messages[0]); } }