问题
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 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.
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