开发者

How to do logging with WPF?

I'm writing a WPF application using a MVVM pattern and using Prism in selected places for loose coupling, and I'd like to have logging messages shown in a window and written to a fil开发者_JS百科e. The subset of messages going each way may not be the same.

I think I should publish a message through the EventAggregator (MS-Prism implementation of observer pattern) and have two objects subscribe: one that updates the LogWindowViewModel and one that logs using the Enterprise Library logger. Is this a good idea or am I duplicating something that's already implemented?


The fact that the log message will be different in each output is the limiting factor.

Extending the block may suffice and defining a CustomTraceListener or ILogFilter may work out for you. This would avoid needing to use the EventAggregator.

It boils down to who has the knowledge of what and where to log. Are the differences driven off values within the logging engine such as severity? Are they instead driven by the consumer of the logging engine and therefore tightly coupled to the class itself? These types of questions will dictate your choice.

Leveraging the extension points in the logging block would be my first choice before having to rely on using the EventAggregator.


I think an idea is fine. There is not so much functionality to be duplicated it seems


I used Common.Logging as data collector, filter and distributor for something comparable and wrote a custom appender for my own processing and ui-output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜