简体   繁体   中英

Log4Net Viewing using a Circular Buffer

I am using Log4Net in a WPF app. I have it working where I am using the NotifyAppender to update a TextBox on my form. 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. 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. 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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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