public void TestFileScope() { var listener = new TestLoggerListener("TestFileScope"); try { Logger.RegisterListener(listener); Action callback; Logger.LogInfo("Not in file scope.", listener.Phase); Assert.Null(listener.TakeAndRemove().File); using (new LoggerFileScope("A")) { Logger.LogInfo("In file A", listener.Phase); Assert.Equal("A", listener.TakeAndRemove().File); using (new LoggerFileScope("B")) { Logger.LogInfo("In file B", listener.Phase); Assert.Equal("B", listener.TakeAndRemove().File); var captured = LoggerFileScope.Capture(); callback = () => { using (LoggerFileScope.Restore(captured)) { Logger.LogInfo("In captured file B", listener.Phase); } }; } Logger.LogInfo("In file A", listener.Phase); Assert.Equal("A", listener.TakeAndRemove().File); callback(); Assert.Equal("B", listener.TakeAndRemove().File); Logger.LogInfo("In file A", listener.Phase); Assert.Equal("A", listener.TakeAndRemove().File); using (new LoggerFileScope("C")) { Logger.LogInfo("In file C", listener.Phase); Assert.Equal("C", listener.TakeAndRemove().File); callback(); Assert.Equal("B", listener.TakeAndRemove().File); } } Logger.LogInfo("Not in file scope.", listener.Phase); Assert.Null(listener.TakeAndRemove().File); callback(); Assert.Equal("B", listener.TakeAndRemove().File); Logger.LogInfo("Not in file scope.", listener.Phase); Assert.Null(listener.TakeAndRemove().File); } finally { Logger.UnregisterListener(listener); } }
public void TestFileScope() { var listener = new TestLoggerListener("TestFileScope"); try { Logger.RegisterListener(listener); Action callback; Logger.LogInfo("Not in file scope.", listener.Phase); Assert.Null(listener.TakeAndRemove().File); using (new LoggerFileScope("A")) { Logger.LogInfo("In file A", listener.Phase); Assert.Equal("A", listener.TakeAndRemove().File); using (new LoggerFileScope("B")) { Logger.LogInfo("In file B", listener.Phase); Assert.Equal("B", listener.TakeAndRemove().File); var captured = LoggerFileScope.Capture(); callback = () => { using (LoggerFileScope.Restore(captured)) { Logger.LogInfo("In captured file B", listener.Phase); } }; } Logger.LogInfo("In file A", listener.Phase); Assert.Equal("A", listener.TakeAndRemove().File); callback(); Assert.Equal("B", listener.TakeAndRemove().File); Logger.LogInfo("In file A", listener.Phase); Assert.Equal("A", listener.TakeAndRemove().File); using (new LoggerFileScope("C")) { Logger.LogInfo("In file C", listener.Phase); Assert.Equal("C", listener.TakeAndRemove().File); callback(); Assert.Equal("B", listener.TakeAndRemove().File); } } Logger.LogInfo("Not in file scope.", listener.Phase); Assert.Null(listener.TakeAndRemove().File); callback(); Assert.Equal("B", listener.TakeAndRemove().File); Logger.LogInfo("Not in file scope.", listener.Phase); Assert.Null(listener.TakeAndRemove().File); } finally { Logger.UnregisterListener(listener); } }
public void TestPhaseScope() { var listener = new TestLoggerListener { LogLevelThreshold = LogLevel.Diagnostic }; var logLevel = Logger.LogLevelThreshold; ILogItem item; try { Logger.LogLevelThreshold = LogLevel.Diagnostic; Logger.RegisterListener(listener); Action <bool> callback; Logger.LogInfo("test no phase scope"); Assert.Null(listener.TakeAndRemove().Phase); using (new LoggerPhaseScope("A")) { Logger.LogInfo("test in phase scope A"); Assert.Equal("A", listener.TakeAndRemove().Phase); using (new LoggerPhaseScope("B")) { Logger.LogInfo("test in phase scope B"); Assert.Equal("A.B", listener.TakeAndRemove().Phase); var captured = LoggerPhaseScope.Capture(); Assert.NotNull(captured); callback = shouldLogPerformance => { using (LoggerPhaseScope.Restore(captured, shouldLogPerformance)) { Logger.LogInfo("test in captured phase scope B"); } }; } // exit scope B. using (new LoggerPhaseScope("C", true)) { Logger.LogInfo("test in phase scope C"); Assert.Equal("A.C", listener.TakeAndRemove().Phase); // run callback in scope C. callback(false); Assert.Equal("A.B", listener.TakeAndRemove().Phase); } // exit scope C. item = listener.TakeAndRemove(); Assert.Equal("A.C", item.Phase); Assert.Equal(LogLevel.Diagnostic, item.LogLevel); } // exit scope A. Logger.LogInfo("test no phase scope"); Assert.Null(listener.TakeAndRemove().Phase); // run callback in no scope. callback(true); Assert.Equal("A.B", listener.TakeAndRemove().Phase); item = listener.TakeAndRemove(); Assert.Equal("A.B", item.Phase); Assert.Equal(LogLevel.Diagnostic, item.LogLevel); Logger.LogInfo("test no phase scope again"); Assert.Null(listener.TakeAndRemove().Phase); } finally { Logger.UnregisterListener(listener); Logger.LogLevelThreshold = logLevel; } }
public void TestPhaseScope() { var listener = new TestLoggerListener { LogLevelThreshold = LogLevel.Diagnostic }; var logLevel = Logger.LogLevelThreshold; ILogItem item; try { Logger.LogLevelThreshold = LogLevel.Diagnostic; Logger.RegisterListener(listener); Action<bool> callback; Logger.LogInfo("test no phase scope"); Assert.Null(listener.TakeAndRemove().Phase); using (new LoggerPhaseScope("A")) { Logger.LogInfo("test in phase scope A"); Assert.Equal("A", listener.TakeAndRemove().Phase); using (new LoggerPhaseScope("B")) { Logger.LogInfo("test in phase scope B"); Assert.Equal("A.B", listener.TakeAndRemove().Phase); var captured = LoggerPhaseScope.Capture(); Assert.NotNull(captured); callback = shouldLogPerformance => { using (LoggerPhaseScope.Restore(captured, shouldLogPerformance)) { Logger.LogInfo("test in captured phase scope B"); } }; } // exit scope B. using (new LoggerPhaseScope("C", true)) { Logger.LogInfo("test in phase scope C"); Assert.Equal("A.C", listener.TakeAndRemove().Phase); // run callback in scope C. callback(false); Assert.Equal("A.B", listener.TakeAndRemove().Phase); } // exit scope C. item = listener.TakeAndRemove(); Assert.Equal("A.C", item.Phase); Assert.Equal(LogLevel.Diagnostic, item.LogLevel); } // exit scope A. Logger.LogInfo("test no phase scope"); Assert.Null(listener.TakeAndRemove().Phase); // run callback in no scope. callback(true); Assert.Equal("A.B", listener.TakeAndRemove().Phase); item = listener.TakeAndRemove(); Assert.Equal("A.B", item.Phase); Assert.Equal(LogLevel.Diagnostic, item.LogLevel); Logger.LogInfo("test no phase scope again"); Assert.Null(listener.TakeAndRemove().Phase); } finally { Logger.UnregisterListener(listener); Logger.LogLevelThreshold = logLevel; } }