有没有一种方法可以设置log4net内存附加程序可以包含的最大错误消息数? [英] Is there a way to set the maximum number of error messages a log4net memory appender can contain?

查看:91
本文介绍了有没有一种方法可以设置log4net内存附加程序可以包含的最大错误消息数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向根记录器添加一个内存附加器,以便我可以连接到应用程序并获取最近的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆