Apologies if I overlooked it but I couldn't immediately find a similar question on SO.
.Net comes with some built-in logging capabilities (essentially, System.Diagnostics.Debug and System.Diagnostics.Trace).
Is there a goo开发者_开发知识库d reason not to use these built-in facilities for logging purposes in a typical LOB application, and instead use log4net, NLog, EntLib logging block or [insert your favourite logging library here]?
EDIT: note that I am more interested in pinpointing the shortcomings of System.Diagnostics w.r.t. logging capabilities, rather than the features of the different logging libraries.
I prefer to use NLog or log4net because it gives me:
- Logging targets. I can chose the best for certain purpose without changing any bit of logging code
- I can log the informations that I need at certain situation thanks to Log Levels
- I can format my Log Entry the way I like, also in different ways for diferent Targets
- Performance is quite ok, thanks for batching
- Im not inventing the wheel
- I can reause this many times
Being able to send your logs to multiple endpoints (syslog, database, event log, etc) can be useful.
I use log4net and it's advantages are that in configuration files you can choose what level of logging you require (Critical, Error, Warning, Information, Debug) and you get things like email logging and rolling log files for free.
For .net, I like using http://netcommon.sourceforge.net/doc-latest/reference/html/logging.html. It's basically a wrapper layer above, so underneath, you can switch logging engines easily. It's very log4net like though.
There is also:
http://commons.apache.org/logging/guide.html
精彩评论