Question

So I have an application where I will be using tracing for logging application activity/errors etc. Most information will go in a log file whereas some errors will go in event viewer too. This application will have lots of classes.
What is the best way of using TraceSource in this case? Should I create a singleton wrapping TestSource class or is there any better way of doing it?

Was it helpful?

Solution

I agree to some extent with @Valdis - log4net and NLog are two examples of very powerful logging frameworks that offer a great deal of flexibility and relatively easy to use configuration (NLog is probably easier to configure than log4net). However, I don't think that is necessary to completely avoid TraceSource. TraceSource is built in so you avoid an extra dependency.

If you are using TraceSource I don't think that a single application wide static TraceSource object is the way to go. I would recommend using more TraceSources, possibly even one per class (that might be overkill, but is a common pattern when using log4net and NLog).

I have put more details in an answer to your other question about when to use more than one TraceSource in an application.

OTHER TIPS

are you strict to use built-in .net eventing and logging infrastructure? I would encourage to use some of the 3rd parties (like logging from Enterprise Library). those are more flexible, more configurable and you do not have a headackes like these - you just write:

Logger.Write(...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top