Is there a way to set the maximum number of error messages that a log4net memory application may contain?

I would like to add a memory application to the root log so that I can connect to the application and get the last 10 events. I just want to save the last 10 years. My concern is that this appender is consuming too much memory. The app is designed for 24/7. Or is there another way?

+6
logging log4net
source share
2 answers

I think you might need to create your own Appender class, which comes from MemoryAppender and overrides the output storage by counting the number of messages currently being displayed. You can store messages in a list and in the Append method determine whether the list has a maximum number of messages. If so, you delete the oldest message and add a new one to the list.

+3
source share

You will need to create a custom appender to store a limited number of logs. For example, MemoryAppender can 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); } } } 
+7
source share

All Articles