Pregunta

I would like to avoid writing my own generic logging interface, and rather use built in Trace functionality, which to start with doesn't require any logging library. Before I address logging libraries, I already have my trace info in at least the Output Window, which at this stage of development is quite adequate.

I would then like to add a logging library to my app, and couple Trace to it with a listener, and not write any more logging code.

What are your opinions on this strategy, and are trace listeners for these logging libraries, or maybe others, like Enterprise Library, available or feasible to quickly implement?

¿Fue útil?

Solución

NLog provides a TraceListener that will route Trace/TraceSource statements to the NLog logging system.

http://nlog-project.org/2010/09/02/routing-system-diagnostics-trace-and-system-diagnostics-tracesource-logs-through-nlog.html

AFAIK log4net does not come with a TraceListener, but it should be easy enough to write one:

How to log Trace messages with log4net?

Also, you didn't ask, but Common.Logging also provides a way to route logging messages (using the Common.Logging abstraction API) to a TraceListener, as well as bridging among the Common.Logging supported platforms.

See Advanced Logging Tasks here:

http://netcommon.sourceforge.net/docs/2.1.0/reference/html/ch01.html

As far as my opinion on your strategy... I think the strategy seems reasonable. I think that I would recommend that you consider using TraceSources rather than the static Trace object. One benefit is that you will have a finer granularity of control (i.e. turn some TraceSources on/off or set them at different levels).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top