Digbyswift is based in Leeds, West Yorkshire offering web and digital solutions. With over a decade of experience in corporate and agency web development, Digbyswift can meet and support your requirements, whether it be MVC or web forms development, Umbraco, bespoke CMS build and maintenance, ecommerce, SEO and Google analytics or even client training. Read more ...

log4net vs NLog

By Digbyswift at April 14, 2011 13:46

This has been covered well in this Stackoverflow article but I was explaining the importance of the differences and of the implementation to a colleague recently.

The implementation is almost identical for each:

  • Both require a configuration file;
  • Logging objects in either are created in much the same way;
  • Both have instance methods on a Logger object allowing you to log debug messages, warning messages errors etc.
private static Logger Log = LogManager.GetLogger(typeof(ThisClass));
public void SomeMethod()
        // some code that may fail
    catch(Exception ex)
        Log.Error("SomeMethod() failed", ex);

The core difference for me though is that log4net is no longer being actively supported. It hasn’t been for years. I’ll admit, all my projects use log4net. Every one of them. But I’m considering changing.

NLog is current and seems to be moving with the goal posts and this gives me some comfort. The advantage that log4net offers is that the way I use it is so basic, i.e. class-level logging, I have to ask myself whether there is any point in changing?

The answer of course is to wrap the implementation of whichever logger is used in a facade pattern. This would allow you to use either as needs be.