Logging to elmah.io from NLog

This post has been adapted as part of our official documentation. To read the most updated version, please check out Logging to elmah.io from NLog

NLog is one of the most popular logging frameworks for .NET. With an active history on almost 10 years, the possibilities with NLog are many and it’s easy to find documentation on how to use it. Choosing weather or not we should integrate NLog and elmah.io was a no-brainer.

To start logging messages from NLog to elmah.io, you need to install the elmah.io.nlog NuGet package:

Install-Package elmah.io.nlog

To configure the elmah.io target, add the following configuration to your app.config/web.config/nlog.config depending on what kind of project you’ve created:

  <add assembly="Elmah.Io.NLog"/>
  <target name="elmahio" type="elmah.io" logId="LOG_ID"/>
  <logger name="*" minlevel="Info" writeTo="elmahio" />

(replace LOG_ID with your log ID)

In the example we specify the level minimum as Info. This tells NLog to log only information, warning, error and fatal messages. You may adjust this but be aware, that your elmah.io log may run full pretty fast, if you log thousands and thousands of trace and debug messages.

Log messages to elmah.io, just as with every other target and NLog:

log.Warn("This is a warning message");
log.Error(new Exception(), "This is an error message");

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