.NET Logging Tools and Libraries

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 exist. 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 are a lot 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 has 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 fail without us 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.

Would your users appreciate fewer errors?

➡️ Reduce errors by 90% with elmah.io error logging and uptime monitoring ⬅️

NLog

While log4net quickly became the default choice, alternatives began to show up. Probably the first real competitor to log4net's dominance was 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 was taken by storm once again. When everyone else was logging text messages, Nicholas 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.

elmah.io in action

elmah.io: Error logging and Uptime Monitoring for your web apps

This blog post is brought to you by elmah.io. elmah.io is error logging, uptime monitoring, deployment tracking, and service heartbeats for your .NET and JavaScript applications. Stop relying on your users to notify you when something is wrong or dig through hundreds of megabytes of log files spread across servers. With elmah.io, we store all of your log messages, notify you through popular channels like email, Slack, and Microsoft Teams, and help you fix errors fast.

See how we can help you monitor your website for crashes Monitor your website