Log4Net MemoryAppender seems to miss high speed log events

后端 未结 1 2025
無奈伤痛
無奈伤痛 2021-01-25 04:59

I am using a log4net MemoryAppender to show my log4net output on a form text box. The relevant part of my config file is:



        
相关标签:
1条回答
  • 2021-01-25 05:26

    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;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题