Logging Frameworks for .NET

Hello World,

Any application out in the real world needs good instrumentation so that when things go wrong (as they will from time to time), one has somewhere to start. Logging has long been a standard and time-tested way for recording context when your application runs into exceptions or suffers a crash. A good logging framework goes a long way in creating a well intstrumented application that is easy to maintain. As the adage goes in developer-land, you may very well be the developer who maintains that app, so better prepare well for a rainy day – coz’ when it rains, it pours!

As .NET is a mature framework, unsurprisingly there a gazillion enterprise grade logging frameworks available – both open source as well as commercial. When looking for a framework, my personal preference is that it should, at a bare minimum, have the following features:

  1. Be actively developed and supported (whether by a thriving and active community or an enterprise) – so that security issues and / or bugs get fixed promptly
  2. Provide a consistent API
  3. Be thread-safe
  4. Provide at least logging to file, eventlog and database out-of-the-box
  5. Be extensible/have a plugin or extensibility point so that custom behavior may be added

And, The Nominees are

NLog and Log4Net are two of the most popular frameworks while MS Enterprise Library also provides a Logging Application Block that is pretty solid. While googling around, I found a commercial solution called SmartInspect that claims to be the super man of logging frameworks as it comes with some pretty awesome features – at a price though! (actually it has a per developer licence and at $199 looks quite pricey IMHO)

Taking a logging framework home

Based on prior experience, I’ve found that it is a wise practice to abstract the core logging API into a custom interface so that your solution isn’t tightly coupled with a logging implementation. You may then build on by creating a Factory that creates an instance of a LoggingAdapter that eventually calls into a concrete logger to log to a configured target (e.g. file).

Turns out there is already an open source library called Common.Logging that provides a simple logging abstraction to switch between different logging implementations. There is current support for log4net, NLog and Enterprise Library logging. The project is on GitHub and is actively developed.

Log File Viewers

It is no good writing logs if you don’t have a good viewer you can use to analyse those log files. Again, at a bare minimum, the viewer must be able to tail a log file (show active logs being written), and provide search and filtering. There are a lot of tools that make the cut:

  1. BareTail from Bare Metal – Has a free as well as paid variant, provides color coding and search
  2. LogExpert – found here – Free and open source, has custom columnizer so can process almost any format
  3. One could use a PowerShell cmdlet to tail log files as described here – free but no colors here!

PS: The company that owns SmartInspect, Gu Rock, has a page that compares features of the most popular logging frameworks here – please note that I have not verified the accuracy of the comparison, there may be changes

They also have a (claimed) comprehensive directory of logging tools here.

Happy Coding!

Tagged with: ,
Posted in .NET, C#
2 comments on “Logging Frameworks for .NET
  1. John Jackson says:

    You’ve linked to Stackify’s (stackify.com) list of how to tail a log file, but they actually have a great error and log management solution, which includes appenders to log4net and Nlog. I use it and it has proven to be invaluable as it helped found the root cause of some issues really fast

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • Comic for July 25, 2017
    Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
%d bloggers like this: