public void AutoFlushTargetWrapperAsyncTest2() { var myTarget = new MyAsyncTarget(); var wrapper = new AutoFlushTargetWrapper(myTarget); myTarget.Initialize(null); wrapper.Initialize(null); var logEvent = new LogEventInfo(); Exception lastException = null; for (int i = 0; i < 100; ++i) { wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(ex => lastException = ex)); } var continuationHit = new ManualResetEvent(false); AsyncContinuation continuation = ex => { continuationHit.Set(); }; wrapper.Flush(ex => { }); Assert.Null(lastException); wrapper.Flush(continuation); Assert.Null(lastException); continuationHit.WaitOne(); Assert.Null(lastException); wrapper.Flush(ex => { }); // Executed right away Assert.Null(lastException); Assert.Equal(100, myTarget.WriteCount); Assert.Equal(103, myTarget.FlushCount); }
public void IgnoreExplicitAutoFlushWrapperTest() { var testTarget = new MyTarget(); var bufferingTargetWrapper = new BufferingTargetWrapper(testTarget, 100); var autoFlushOnLevelWrapper = new AutoFlushTargetWrapper(bufferingTargetWrapper); autoFlushOnLevelWrapper.Condition = "level > LogLevel.Info"; autoFlushOnLevelWrapper.FlushOnConditionOnly = true; testTarget.Initialize(null); bufferingTargetWrapper.Initialize(null); autoFlushOnLevelWrapper.Initialize(null); AsyncContinuation continuation = ex => { }; autoFlushOnLevelWrapper.WriteAsyncLogEvent(LogEventInfo.Create(LogLevel.Trace, "*", "test").WithContinuation(continuation)); Assert.Equal(0, testTarget.WriteCount); Assert.Equal(0, testTarget.FlushCount); autoFlushOnLevelWrapper.WriteAsyncLogEvent(LogEventInfo.Create(LogLevel.Fatal, "*", "test").WithContinuation(continuation)); Assert.Equal(2, testTarget.WriteCount); Assert.Equal(1, testTarget.FlushCount); autoFlushOnLevelWrapper.WriteAsyncLogEvent(LogEventInfo.Create(LogLevel.Trace, "*", "Please do not FlushThis").WithContinuation(continuation)); Assert.Equal(2, testTarget.WriteCount); Assert.Equal(1, testTarget.FlushCount); autoFlushOnLevelWrapper.Flush(continuation); Assert.Equal(2, testTarget.WriteCount); Assert.Equal(1, testTarget.FlushCount); }