简体   繁体   English

使用循环缓冲区查看Log4Net

[英]Log4Net Viewing using a Circular Buffer

I am using Log4Net in a WPF app. 我在WPF应用程序中使用Log4Net。 I have it working where I am using the NotifyAppender to update a TextBox on my form. 我在使用NotifyAppender更新表单上的TextBox地方工作。 This comes in with the oldest on the top, newest on the bottom. 顶部是最旧的​​,底部是最新的。

I need to reverse that and have the newest on top. 我需要扭转这种情况,并在最新的位置。 I would also like to be able to "freeze" the updating of the view so that a user can scroll through the messages, and then be able to "unfreeze" it. 我还希望能够“冻结”视图的更新,以便用户可以滚动查看消息,然后“解冻”它。 Any messages that where "bufferred" can now be displayed. 现在可以显示“ bufferred”所在的所有消息。 I'm assuming I need to capture the messages and place them in a collection, sort it, and then display them in the view but I'm not sure how to capture the messages. 我假设我需要捕获消息并将它们放入集合中,对其进行排序,然后在视图中显示它们,但是我不确定如何捕获消息。

What is the best way to accomplish this? 做到这一点的最佳方法是什么?

You could consider using a MemoryAppender and access this somehow from your WPF application. 您可以考虑使用MemoryAppender,并从WPF应用程序中以某种方式访问​​它。 I think however that you would be better of to write your own appender (Hint: Check out the source code of the MemoryAppender) and allow this appender to communicate more directly with your application (ie you could use a service locator in order to connect to a service that receives your log messages. This service in turn is used by your ViewModel (assuming you use MVVM) for populating your TextBox . This probably works best if you use some IoC container, but this is not strictly necessary.) 不过,我认为您最好编写自己的附加程序(提示:查看MemoryAppender的源代码),并允许该附加程序与应用程序更直接地通信(即,可以使用服务定位器来连接到接收日志消息的服务。ViewModel使用该服务(假设您使用MVVM)来填充TextBox 。如果您使用某些IoC容器,这可能效果最好,但这不是绝对必要的。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM