Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set the maximum number of error messages a log4net memory appender can contain?

I would like to add a memory appender to the root logger so that I can connect to the application and get the last 10 events. I only ever want to keep the last 10. I am worried about this appender consuming all too much memory. The application is designed to run 24/7. Or is there another way?

like image 920
uriDium Avatar asked Mar 10 '10 10:03

uriDium


1 Answers

You would need to create a custom appender to store a limited number of logs. For example the MemoryAppender could be subclassed as follows:

public class LimitedMemoryAppender : MemoryAppender
{
    override protected void Append(LoggingEvent loggingEvent) 
    {
        base.Append(loggingEvent);
        if (m_eventsList.Count > 10)
        {
            m_eventsList.RemoveAt(0);
        }
    } 
}
like image 108
Nicko Avatar answered Sep 19 '22 01:09

Nicko