public void LoggingExceptionTest() { const string TITLE_MSG = "Exception Message"; const string EXCEPTION_MSG = "ImageGen Service Logging Exception-test"; var appender = new MemoryAppender(); log4net.Config.BasicConfigurator.Configure(appender); var exc = new Exception(EXCEPTION_MSG); Log.Fatal(exc); Log.Fatal(TITLE_MSG, exc); Thread.Sleep(1000); var logEntries = appender.GetEvents(); // Remove Listeners Log4NetStandardLogListener.Clear(); LogManager.Manager.ClearListeners(); // Check for Exception message Assert.IsTrue(logEntries[0].RenderedMessage.Contains(EXCEPTION_MSG)); // Check for text message Assert.IsTrue(logEntries[1].RenderedMessage.Contains(TITLE_MSG)); }
public async Task TransportHost_LogsError_WhenStartFails() { // arrange LogManager.Manager.AddListener(Log4NetStandardLogListener.Instance); var appender = new MemoryAppender(); log4net.Config.BasicConfigurator.Configure(appender); const string errorMessage = "error message"; _mockNServiceBusServer.Setup(m => m.Start(It.IsAny <string>(), It.IsAny <bool>())).ReturnsAsync(errorMessage); // act await _transportHost.Start(false, () => true); // Give the logging time to finish Thread.Sleep(1000); var logEntries = appender.GetEvents(); Log4NetStandardLogListener.Clear(); LogManager.Manager.ClearListeners(); // assert Assert.AreEqual(1, logEntries.Length); Assert.AreEqual(errorMessage, logEntries.Single().RenderedMessage); _mockNServiceBusServer.Verify(m => m.Start(It.IsAny <string>(), It.IsAny <bool>()), Times.Once); }
public void LoggingBasicTest() { const string DEBUG_MSG = "ImageGen Service Logging Debug-Test."; const string INFO_MSG = "ImageGen Service Logging Info-Test."; const string WARN_MSG = "ImageGen Service Logging Warn-Test."; const string ERROR_MSG = "ImageGen Service Logging Error-Test."; const string FATAL_MSG = "ImageGen Service Logging Fatal-Test."; var appender = new MemoryAppender(); log4net.Config.BasicConfigurator.Configure(appender); Log.Debug(DEBUG_MSG); Log.Info(INFO_MSG); Log.Warn(WARN_MSG); Log.Error(ERROR_MSG); Log.Fatal(FATAL_MSG); // Let it finish... Thread.Sleep(1000); // Get all Five log Entries from Memory Appender var logEntries = appender.GetEvents(); var appenders = log4net.LogManager.GetRepository().GetAppenders(); // Remove Listeners Log4NetStandardLogListener.Clear(); LogManager.Manager.ClearListeners(); // Check the number of logged messages Assert.IsTrue(logEntries.Length == 5); // Debug Message type should be first by priority Assert.IsTrue(logEntries[0].RenderedMessage.Equals(DEBUG_MSG)); // Error Message must be the last one Assert.IsTrue(logEntries[4].RenderedMessage.Equals(ERROR_MSG)); // Must be at least One Appender Assert.IsTrue(appenders.Length >= 1); }
public bool Stop(HostControl hostControl) { try { Log.Info("ImageGen Service is stopping..."); _nServiceBusServer.Stop().Wait(); // Keep it for testing purposes but make it safe. try { _server.CloseAsync().Wait(); _server.Dispose(); } catch (Exception e) { // Debug in order that customers do not see it in the production Log.DebugFormat("Failed to stop self host web server.", e); } BrowserPool.Dispose(); Log.Info("ImageGen Service is stopped."); } catch (Exception e) { Log.Error(e); } finally { // Remove Log Listener Log4NetStandardLogListener.Clear(); LogManager.Manager.ClearListeners(); } return(true); }
public void TestCleanup() { // Remove Listeners Log4NetStandardLogListener.Clear(); LogManager.Manager.ClearListeners(); }