.NET Logging Tools and Libraries

Thomas Ardal, June 10, 2016

It's a jungle out there, as they say. The community around .NET logging tools and frameworks is growing every day and multiple options covering the same basic needs exists. This definitive guide will help you through the large offer of frameworks and make it possible for you to choose the right logging strategy.

What's Logging?

Before we dig into the large number of logging frameworks, let's spend a bit of time discussing the terms related to logging. Logging as a single term, means storing messages from your application somewhere. These messages are often used for debugging errors, but I've seen log data used for multiple other purposes like creating a dashboard, monitoring updates, audit trails etc. The nice thing about logging is, that you're in control if a message should go into the log or not.

As mentioned, most people use logging frameworks for logging exceptions and other messages making it possible to debug errors in production. All of the frameworks mentioned in this post support error logging, while few actually build error management features on top of the log. Error management actually helps you monitor and deal with your errors in a more intelligent way than having to look through log files. More on that subject later.

Logging Frameworks

We've compiled a list of logging frameworks for .NET. There's a great deal of options out there, but a lot of them are no longer maintained. The list provided in this section contains the popular choices.

log4net

Probably the oldest logging framework on the block, log4net have existed pretty much since .NET was introduced. log4net was originally an internal Apache log4j port developed by Neoworks Limited back in 2001. The project quickly moved to Sourceforge (the GitHub of 2001) and was released under the Apache license. Since that time, log4net has been one of the most popular choices in the .NET world for adding logging to applications.

log4net works with the concept of appenders, where log messages can be routed to different data stores. A lot of appenders have been implemented during the years, like logging to the file system, SQL Server, HTTP endpoints and even NoSQL databases. Being unstructured text messages, log4net and NoSQL don’t exactly go hand in hand.

ELMAH

Back in 2004, Atif Aziz spotted something important. Websites sometimes fails without we as web developers actually spotting the errors. That's why he decided to create ELMAH. While ELMAH can be used as a logging framework, the focus is entirely upon errors. While we still see people misusing ELMAH to log debug messages, ELMAH is after 12 years still the best choice of logging uncaught errors in your websites.

NLog

While log4net quickly became the default choice, alternatives began to show up. Probably the first real competitor to log4net's dominance were NLog. Originally developed by Jarek Kowalski and with pull requests from almost 100 people, NLog is a great alternative. While log4net pretty much stood still from 2006, NLog just kept going. While Jarek seemed to pull the plug when starting at Google, the community seemed to step up and new releases are still flowing.

Like log4net, NLog contains multiple log targets, and is able to log messages to various data stores.

Serilog

In 2013, the .NET logging framework were taken by storm once again. When everyone else were logging text messages, Micholas Blumhardt did something new: structured logging. Unlike existing logging frameworks, Serilog introduced .NET developers to structured event data rather than dumb text messages. Serilog quickly became one of the fastest moving projects in the .NET community and still is. We really recommend you to look into Serilog for logging messages from your .NET apps.

Error Management

We wanted to put some words on the terms Error Management. We often talk to people that don't realize, that there's a big difference between Error Logging and Error Management. While log4net, NLog and Serilog are great choices for logging text-based or structured log messages to a text file or a database, this is simply not enough to monitor your websites and act on errors. Having a log file is one thing. Even with cool storage choices like Seq and Elasticsearch, having a system for monitoring and handling errors is an essential part of web application development today.

A lot of choices showed up during the last few years. elmah.io, New Relic, Raygun and Stackify are all examples of popular choices for implementing error management. All run in the Cloud and provides easy integration with your .NET websites. When looking through the different solutions, some basic features work pretty much the same way, while others vary by product. Some focus on supporting a lot of different programming languages, others on integrating with logging frameworks and some on integrating with third party systems like Slack and GitHub.

At elmah.io, we are working hard to create the best error management system for .NET web applications. We support all the major logging frameworks and tools for .NET like ELMAH, log4net, NLog and Serilog. We also provide some unique features for .NET developers like Visual Studio integration and one-click installation through NuGet. We definitely want you to try out elmah.io for your error management needs in .NET.


This post was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening and help you fix errors fast.

Monitor your website



Comments