public void should_return_special_log_event_when_no_more_log_event_are_available() { var log = LogManager.GetLogger(typeof(LogManagerTests)); var actualLogEvents = new List <ILogEvent>(); for (var i = 0; i < 10; i++) { actualLogEvents.Add(log.Debug()); } var unavailableEvent = log.Debug(); Check.That(actualLogEvents.OfType <LogEvent>().Count()).Equals(actualLogEvents.Count); Check.That(unavailableEvent).IsInstanceOf <ForwardingLogEvent>(); var signal = _testAppender.SetMessageCountTarget(actualLogEvents.Count); for (var i = 0; i < actualLogEvents.Count; i++) { var actualLogEvent = actualLogEvents[i]; actualLogEvent.Append(i).Log(); } signal.Wait(TimeSpan.FromMilliseconds(100)); Check.That(log.Debug()).IsInstanceOf <LogEvent>(); }
public void should_run_test() { const int threadMessageCount = 1000 * 1000; const int threadCount = 5; const int totalMessageCount = threadMessageCount * threadCount; var timer = Stopwatch.StartNew(); var logger = LogManager.GetLogger(typeof(PerformanceTests)); var signal = _testAppender.SetMessageCountTarget(totalMessageCount); var utcNow = DateTime.UtcNow; Parallel.For(0, threadCount, i => { for (var k = 0; k < threadMessageCount; k++) { logger.Info().Append("Hello ").Append(42).Append(utcNow).Append(42.56).Append(" this is a relatlively long message ").Append(12345.4332m).Log(); } }); var timedOut = !signal.Wait(TimeSpan.FromSeconds(10)); timer.Stop(); if (timedOut) { Assert.Fail("Timeout"); } Console.WriteLine($"Total message count : {totalMessageCount:N0} messages"); Console.WriteLine($"Thread message count : {threadMessageCount:N0} messages"); Console.WriteLine($"Thread count : {threadCount} threads"); Console.WriteLine($"Elapsed time : {timer.ElapsedMilliseconds:N0} ms"); Console.WriteLine($"Message rate : {totalMessageCount / timer.Elapsed.TotalSeconds:N0} m/s"); Console.WriteLine($"Average log cost : {timer.ElapsedMilliseconds * 1000 / (double)totalMessageCount:N3} µs"); }