This line:
this.Evaluator = new log4net.Core.LevelEvaluator(Level.Off);
tells the application to flush the buffer when a message is received with a level equal to or higher by the evaluator . Level.Off will block all events.
Update: after tracing by log4net source again. I do not understand why buffering does not work for you.
Update2: I was at a dead end, but again I forgot that for log4net appenders applications ActivateOptions is required to be called after changing the settings. Until ActivateOptions is called, an internal circular buffer is not created and buffering will not be performed.
So, making a quick test application:
public sealed class MyBufferingAppender: BufferingAppenderSkeleton { public MyBufferingAppender() { BufferSize = 3; ActivateOptions(); } public readonly List<LoggingEvent> SentEvents = new List<LoggingEvent>(); protected override void SendBuffer(LoggingEvent[] events) { SentEvents.AddRange(events); } }
... and a quick test:
[Test] public void DoAppend_BuffersEvents() { var appender = new MyBufferingAppender(); appender.DoAppend(new LoggingEvent( new LoggingEventData {Level = Level.Error, Message = "Hello world"})); Assert.That(appender.SentEvents, Has.Count(0)); }
The test passes (on my machine at least :).
Peter Lillevold
source share