Reputation: 2714
As I'm currently setting up Logging in my (Asp.Net Web Api) application I was reading about best practices according logging. I came along this question about logging best practices.
I was going the Ninject
-> Logging Extensions
-> Nlog / Log4Net
way, but this question (or should I say answer) made me think a second time.
At the moment I have tracing enabled, log every here and there and it feels a bit messy to have logs and traces which don't add up together.
I think that when I switch to Diagnostics Tracing and build on top of what the framework already gives me I would end up with a more complete trace. A trace which tells a complete story sounds more useful to me then a separate trace and log which both know about a part of the story. And of course I could always separate things again with listeners and filters.
But at the other hand I always learned:
Logging != Tracing
So this leaves me with the question, should I drop the logging framework, it's the starting phase of the project, or should I stick with it?
And if I drop the logging framework, should I use a interface in case we ever wanna switch to another logging/tracing framework again, or can I just make a dependency on System.Diagnostics?
Upvotes: 4
Views: 3826
Reputation: 925
I have tried the Log4NET path, and looked at Ninject.
From what I have found, I would say that transforming Diagnotisics.Trace into a logging framework is much more productive than trying to deal with the weight of any of the logging frameworks I've found. (And I agree that Trace != Logging)
Perhaps I am a control freak, but I don't want a ton of opinions introduced into my code base. I want tools, not a straightjacket.
There is a bit of work to build up Trace to a logging framework, but it is highly re-usable as it is just core diagnostics dll that you probably already have in your program if for nothing else then StopWatch for timing.
Anyway, just my opinion, but I much prefer the Diagnostics.Trace route. Consider looking at: http://www.codeproject.com/Articles/2680/Writing-custom-NET-trace-listeners - It is old but will show you what is necessary to roll your own.
Upvotes: 7