TraceListener headers and footers

拟墨画扇 提交于 2020-01-15 04:57:49

问题


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.


回答1:


Here is a good article on how custom TraceListeners 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.

There is also some discussion of this issue in this SO thread.

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.

Good luck!



来源:https://stackoverflow.com/questions/12685581/tracelistener-headers-and-footers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!