public void NothingToFlushTest() { var senderFactory = new MySenderFactory(); var target = new NetworkTarget(); target.Address = "tcp://${logger}.company.lan/"; target.SenderFactory = senderFactory; target.Layout = "${message}"; target.KeepConnection = true; target.Initialize(null); var mre = new ManualResetEvent(false); AsyncContinuation flushContinuation = ex => { mre.Set(); }; target.Flush(flushContinuation); mre.WaitOne(); target.Close(); string expectedLog = @""; Assert.AreEqual(expectedLog, senderFactory.Log.ToString()); }
public void NetworkTargetMultipleConnectionsTest() { var senderFactory = new MySenderFactory(); var target = new NetworkTarget(); target.Address = "tcp://${logger}.company.lan/"; target.SenderFactory = senderFactory; target.Layout = "${message}"; target.KeepConnection = true; target.Initialize(null); var exceptions = new List<Exception>(); var mre = new ManualResetEvent(false); int remaining = 3; AsyncContinuation asyncContinuation = ex => { lock (exceptions) { exceptions.Add(ex); if (--remaining == 0) { mre.Set(); } } }; target.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "logger1", "msg1").WithContinuation(asyncContinuation)); target.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "logger2", "msg2").WithContinuation(asyncContinuation)); target.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "logger3", "msg3").WithContinuation(asyncContinuation)); mre.WaitOne(); foreach (var ex in exceptions) { if (ex != null) { Assert.Fail(ex.ToString()); } } mre.Reset(); AsyncContinuation flushContinuation = ex => { mre.Set(); }; target.Flush(flushContinuation); mre.WaitOne(); target.Close(); string expectedLog = @"1: connect tcp://logger1.company.lan/ 1: send 0 4 2: connect tcp://logger2.company.lan/ 2: send 0 4 3: connect tcp://logger3.company.lan/ 3: send 0 4 1: flush 2: flush 3: flush 1: close 2: close 3: close "; Assert.AreEqual(expectedLog, senderFactory.Log.ToString()); }