TraceListener页眉和页脚 [英] TraceListener headers and footers
问题描述
编写自定义TraceListener时,如何强制将writeheader,数据/消息和writefooter设为一个谨慎的记录?具体而言,有问题的自定义跟踪侦听器将写入非基于文件的源,例如数据库或事件流.我需要忽略TraceListener中的writeHeader,writefooter基本方法,或者以某种方式将其打包到单个write事件中.
When writing a custom TraceListener how can I force the writeheader, the data/messsage, and the writefooter to be one discreet record? Specifically the custom tracelisteners in question write to a non file based source, such as database or event stream. I need to either have the writeHeader, writefooter base methods in TraceListener be ignored or somehow packaged into a single write event.
推荐答案
TraceEvent 调用.
Here is a good article on how custom TraceListener
s work, which also explains when and wh WriteHeader
and WriteFooter
are called. The trick to avoiding WriteHeader
and WriteFooter
is apparently to override the TraceData and/or TraceEvent calls.
最后,我鼓励您看一下 Ukadc.Diagnostics ,它是一个非常酷的库用于扩展System.Diagnostics
的功能,并提供了一种不错的方式来实现类似于log4net/NLog的输出格式.在此SO线程中对此库进行了一些讨论. .
Finally, I would encourage you to take a look at Ukadc.Diagnostics it is a pretty cool library for extending System.Diagnostics
and provides, among other features, a nice way to achieve some log4net/NLog-like output formatting. There is a little bit of discussion about this library in this SO thread.
祝你好运!
这篇关于TraceListener页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!