I am using a log4net MemoryAppender to show my log4net output on a form text box. The relevant part of my config file is:
I assume the following happens: While you are writing your log messages in the text box, new messages are logged. When you clear the messages in the appender you also remove these new messages, which are not written to the text box.
You could improve the situation by clearing the appender before starting to write messages to the text box but I think you should create your own memory appender and provide a method that returns the messages and clears the array in one step. Something like this:
public class MyMemoryAppender : MemoryAppender
{
public LoggingEvent[] GetAndClearEvents()
{
lock (m_eventList.SyncRoot)
{
var events = (LoggingEvent[]) m_eventsList.ToArray(typeof(LoggingEvent));
m_eventsList.Clear();
return events;
}
}
}