有没有一种方法可以设置log4net内存附加程序可以包含的最大错误消息数? [英] Is there a way to set the maximum number of error messages a log4net memory appender can contain?
问题描述
我想向根记录器添加一个内存附加器,以便我可以连接到应用程序并获取最近的10个事件.我只想保留最后10个.我担心此追加器会消耗太多内存.该应用程序旨在运行24/7.还是有另一种方法?
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?
推荐答案
我想,您可能需要创建一个自定义的Appender类,该类从MemoryAppender
派生,并通过计算当前显示的消息数来覆盖输出存储.您可以将消息存储在列表中,然后使用Append
方法确定列表中是否已具有最大数量的消息.如果是这样,则删除最旧的消息,然后将新的消息添加到列表中.
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.
这篇关于有没有一种方法可以设置log4net内存附加程序可以包含的最大错误消息数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!