views:

1352

answers:

5

I need a logging framework in my application. I have two candidates: Log4Net and Logging from Application Block. Which is better? any specific advantage to any of them?

Thanks

+13  A: 

I have found Log4Net to be simpler to setup and use. The problem with Enterprise Library application blocks is they tend to include everything and the kitchen sink and can make something seemingly simple (like logging) into something really complicated. Also because Log4Net is used with nHibernate which I also use then I already have it there ready to go.

Craig
+4  A: 

My opinion ... Log4Net works, performs well and is stable (perhaps too stable given frequency of releases if you know what I mean).

If you need logging it is highly unlikely that you don't need other functionality exposed by Enterprise Library, you'd be on the Microsoft road map, benefit from regular updates, have tool support (e.g. configuration tool) and there is always the much maligned documentation which is far superior than you will get with Open Source.

I think my preference is clear! Enterprise Library all the way.

MS Documentation might appear good on the surface, until you're really looking for something.
JL
+8  A: 

I would go for log4net unless you are already using Enterprise Library for other functionality. I find Enterprise Library to be a bit heavy weight and takes a bit more code to actually do the logging.

log4net has the following advantages;

  • Fast and flexible
  • Hierarchical, named logging categories
  • Multiple logging levels
  • Output to multiple logging targets
  • Dynamic XML Configuration
  • Thread Safe
  • Format of logs is easily changed
  • Proven architecture (log4j)
  • Modular and extensible design
  • Support for multiple frameworks
  • A strong community behind it.

I have been using log4net for a few years now and whenever I need to do something out of the box, I am surprise how easy it ends up being.

Rob Prouse
When you say "log4net hes the following advantages", does that mean, that Enterprise Library does not support all of these features?
M4N
+2  A: 

Log 4 net is nice: great features, but it takes some time and effort to master the configuration especially when the default outputs do not suffice and you need to extend it.

Enterprise Library is heavy weight, not sure where they are going (there have been some breaking changes between releases especially in the DAB). So I personally stay away from it.

I am currently looking at nLog (heard some very nice things about it)

UPDATE: I am currently loving nlog. One particular thing I would like to mention is the ease of configuring the loglevel from within code. Usage example: - user experiences bug - we ask to set the loglevel to trace (a menu option) and execute the same steps - we ask to email the logfile to us. (another menu option)

Cohen
+1  A: 

A simple example of log4net console app Bellow is the configuration file also

YordanGeorgiev