My Account account_circle

Overview of .NET Logging Tools and Frameworks

Please note: This article is obsolete and we have created its own website with links to .NET logging articles, tools and frameworks: DotNetLogging.com.

Introduction
How It Works
.NET Logging Tools and Frameworks
Closing Notes

Introduction

There are different logging solutions available for .NET. All these .NET logging frameworks and tools have one thing in common: they help you and your customers to identify and solve issues with your applications. The different logging frameworks have both their advantages and disadvantages. This article tries to give you an overview of the different logging frameworks and tools for .NET.

How It Works

All the logging frameworks work basically the same: you as an application developer include one of the libraries into your programs and add logging statements to your code. If you start your application and logging is enabled, logging information is sent to the configured logging destination like a log file or monitoring application.

The logged information gives you a good understanding about processed data, warnings, errors and more. By including log statements at strategic and important points in your code you will always know what lead to a specific error, be able to figure out a configuration problem and help your customers solve issues.

The following logging example for C# and .NET uses SmartInspect – the logging tool developed by my company Gurock Software. The example logs some basic messages, objects and variables to a log file. Please note that this example would work in Visual Basic .NET with only minor modifications:

using System;
using Gurock.SmartInspect;

public class EntryPoint
{
   public static void Main(string[] args)
   {
      SiAuto.Si.Connections = @"file(filename=c:\log.sil)";
      SiAuto.Si.Enabled = true;

      SiAuto.Main.LogMessage("This is a message!");
      SiAuto.Main.LogError("This is an error!");

      SiAuto.Main.LogValue("MyInt", 5);
      SiAuto.Main.LogSql("GetAllCustomers", 
          "SELECT * FROM customers");
      SiAuto.Main.LogObject("Main", SiAuto.Main);

      SiAuto.Main.Watch("MyWatch", 2);
      SiAuto.Main.Watch("MyWatch", 7);
   }
}

SmartInspect ships with a useful log viewer application which is called the SmartInspect Console. When you open the log file with the Console, you can view, filter and analyze it:

SmartInspect Console with the opened log file
SmartInspect Console with the opened log file (larger image)

Additionally to log files, most logging tools support real-time logging over either TCP/IP or named pipes. This can be useful during development and for monitoring server applications in production, for example.

.NET Logging Tools and Frameworks

The following list of .NET logging tools and frameworks should give you a good starting point for evaluating and finding the right tool for you.

  • SmartInspect Professional

    SmartInspect Professional is an advanced logging tool with unified logging libraries for .NET, Java and Delphi. SmartInspect has been developed by my company Gurock Software. The main difference between SmartInspect and other logging solutions is the powerful SmartInspect Console with rich monitoring, filtering and analyzation features.

  • Apache Foundation’s log4net

    Log4net is Apache Foundation’s .NET equivalent to log4j – one of the first logging frameworks for Java. Log4net is a library-only logging framework which can log basic messages. Because it only supports basic messages, it is very flexible in where the logging information is stored. Log4net is open source and can be downloaded from the project website.

  • Logging in the Enterprise Library

    Microsoft is shipping a .NET logging library as an application block for its Enterprise Library. Besides the typical logging destinations like log files, this logging framework offers the functionality to log to a database or send log files via email. This library is free and can be downloaded from Microsoft’s website.

  • NLog Logging Library

    NLog is another open source logging library for .NET. It is similar to log4net and the author of NLog tries to model the API after it. NLog can be downloaded on its project website for free.

  • ObjectGuy Framework

    The .NET Logging Framework from The Object Guy is yet another open source logging framework for .NET. It is similar to log4net and NLog and supports different logging destinations. The author of this logging framework is offering a similar library for Java, too.

Closing Notes

If you are interested in logging and increasing the quality of your software or in having a useful tool to support your customers, get one of the logging tools and get it integrated into your application. Depending on the logging tool, integrating it and starting logging should only take a few minutes. For comments or questions, do not hesitate to email me.