public void Flush_ThrowsException_LogContinuationCalledWithCorrectExceptions() { // Arrange var target = new ThrowingInitializeTarget(false); Exception retrievedException = null; AsyncContinuation asyncContinuation = ex => { retrievedException = ex; }; target.Initialize(new LoggingConfiguration()); LogManager.ThrowExceptions = false; // Act target.Flush(asyncContinuation); // Assert Assert.NotNull(retrievedException); //note: not wrapped in NLogRuntimeException, not sure if by design. Assert.IsType <TestException>(retrievedException); }
public void WriteAsyncLogEvent_WriteAsyncLogEventThrowsException_LogContinuationCalledWithCorrectExceptions() { // Arrange var target = new ThrowingInitializeTarget(false); Exception retrievedException = null; var logevent = LogEventInfo.CreateNullEvent().WithContinuation(ex => { retrievedException = ex; }); target.Initialize(new LoggingConfiguration()); LogManager.ThrowExceptions = false; // Act target.WriteAsyncLogEvent(logevent); // Assert Assert.NotNull(retrievedException); //note: not wrapped in NLogRuntimeException, not sure if by design. Assert.IsType <TestException>(retrievedException); Assert.Equal("Write oops", retrievedException.Message); }
public void WriteAsyncLogEvent_InitializeThrowsException_LogContinuationCalledWithCorrectExceptions() { // Arrange var target = new ThrowingInitializeTarget(true); Exception retrievedException = null; var logevent = LogEventInfo.CreateNullEvent().WithContinuation(ex => { retrievedException = ex; }); LogManager.ThrowExceptions = false; target.Initialize(new LoggingConfiguration()); LogManager.ThrowExceptions = true; // Act target.WriteAsyncLogEvent(logevent); // Assert Assert.NotNull(retrievedException); var runtimeException = Assert.IsType <NLogRuntimeException>(retrievedException); var innerException = Assert.IsType <TestException>(runtimeException.InnerException); Assert.Equal("Initialize says no", innerException.Message); }