有没有办法设置 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要创建一个自定义附加程序来存储有限数量的日志。例如,
MemoryAppender
可以按如下方式进行子类化:You would need to create a custom appender to store a limited number of logs. For example the
MemoryAppender
could be subclassed as follows:我想,您可能需要创建一个派生自 MemoryAppender 的自定义 Appender 类,并通过计算当前显示的消息数来覆盖输出存储。您可以将消息存储在列表中,并在
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 theAppend
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.