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?
views:
28answers:
2
+1
Q:
Is there a way to set the maximum number of error messages a log4net memory appender can contain?
+2
A:
I guess, you may need to create a custom Appender class that derives from MemoryAppender
and overrides the output storage by counting the number of messages currently displayed. You can store messages in a list, and, in the Append
method, determine if the list already has maximum number of messages. If so, you delete the oldest message and add the new one to the list.
Kerido
2010-03-10 10:18:14
I was hoping to avoid writing my own appender. Also I would rather use a queue and dequeue/enqueue messages.
uriDium
2010-03-10 13:57:32
+1
A:
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)
{
super.Append(loggingEvent);
if (m_eventsList.Count > 10)
{
m_eventsList.Remove(0);
}
}
}
Nicko
2010-03-26 15:02:36