Cloud logging for NLog

elmah.io and NLog go hand in hand!

NLog in the Cloud

The elmah.io target for NLog sends the messages you already log with NLog to the cloud, where they are searchable in one place and can notify your team about new errors. Add one NuGet package and a few lines of configuration, and keep your other targets as they are. The target is open source and officially supported by the elmah.io team, and all messages are synced with elmah.io's infrastructure hosted on Microsoft Azure.

Configuration is up to you. Add the target to nlog.config, app.config or web.config, set it up in appsettings.json, or create it in C# code. A rule decides which levels are sent, so you can start with information and above and change it later. Your other targets keep working as before.

Structured logging with event properties

Already using NLog event properties and structured logging? Both are extracted before sending off to elmah.io and treated as custom properties with all of the benefits that come with that feature. Search log messages generated by a specific user or by the server causing errors.

Properties in the message template, like {FirstName}, are logged together with the message. Properties added through LogEventInfo, the fluent API or scope properties end up on the Data tab, and reserved property names like User fill the dedicated fields in elmah.io. That makes the values you already log something you can filter and group by.

Search everything you log

Like any other message logged to elmah.io, everything is searchable through the UI. We even support searching by event property names. We automatically map the information given by NLog to individual fields on elmah.io. By using full-text search and search filters, you can run advanced searches across all of your log messages.

Properties are searchable by name, so you can look for a specific user or a property value you log. Combine full-text search with filters on things like severity, application and time to narrow a long log down to the messages that matter.

Fully documented

Not an expert in NLog configuration? No worries, fully documented elmah.io and NLog are available through NuGet. We even provide you with sample code to get up and running. How you want to configure NLog is up to you. We support configuration through app/web.config, nlog.config, appsettings.json and C# code. By utilizing NLog's layout renderers, you can even share configuration between NLog and other elmah.io integrations.

The documentation covers the whole target, not only the basic setup. Use message hooks to decorate every message with a version number or attach source code, filter out messages you do not want to store, and handle errors if logging to elmah.io fails. Set the application name, version and category on your messages, and log custom properties with LogEventInfo, the fluent API or scope properties.

Read the NLog documentation or browse the samples on GitHub.

Let your AI agent read your NLog errors

Connect Claude Code, Cursor, VS Code or Visual Studio to the elmah.io MCP server. Your agent can list new errors, read the stack trace and message details, check what changed after a deployment, and mark an error as fixed when you ask.

AI chat - example conversation
What are the most frequent errors in my production log this week?
The top error is a TimeoutException in PaymentService.Charge, 87 occurrences, mostly in the evening. The second is a NullReferenceException in OrderService.Calculate, 31 occurrences.

In Claude Code, add the server with one command:

claude mcp add --transport http --client-id claudecode elmahio https://mcp.elmah.io/mcp

The MCP server is included on every plan and is currently in beta. Set up the MCP server.

Set up in a few lines

Install the NuGet package, add the target and a rule to your nlog.config with your API key and log ID, and log as usual.

dotnet add package Elmah.Io.NLog
<targets>
  <target name="elmahio" type="elmah.io, Elmah.Io.NLog" apiKey="API_KEY" logId="LOG_ID"/>
</targets>

<rules>
  <logger name="*" minlevel="Info" writeTo="elmahio" />
</rules>
log.Warn("This is a warning message");
log.Error(new Exception(), "This is an error message");

The rule above logs information, warning, error and fatal messages. Raise minlevel if you only want warnings and above in elmah.io, and keep your other targets as verbose as you like. Avoid NLog 4.6.0, which has a bug that stops the elmah.io target from loading. Your API key and log ID are shown on the install page when you sign up. Read the full setup guide.

How it looks

Here is what elmah.io logs for an NLog message:

  • The message, with its severity and logger name.
  • Every event property as its own field on the Data tab, including structured properties like {FirstName}.
  • Reserved property names fill dedicated fields, for example User.
  • The exception type and stack trace when you pass an exception.
An unhandled exception in elmah.io, with the request and the stack trace.

Frequently asked questions

Can I keep my existing NLog targets and add elmah.io?

Yes. Add the elmah.io target and a rule that writes to it, and keep your file, console and other targets as they are.

Set minlevel on the rule that writes to elmah.io, for example to Warn. A rule with minlevel="Info" sends information, warning, error and fatal messages.

Yes. In appsettings.json, use the NLog.Extensions.Logging package. In code, create an ElmahIoTarget and add it to your LoggingConfiguration.

Pass the exception to the logger, for example log.Error(new Exception(), "This is an error message"). The exception type and stack trace are logged with the message.

Yes. Connect the elmah.io MCP server to Claude Code, Cursor, VS Code or Visual Studio. It is included on every plan and is currently in beta.

Get started with elmah.io
elmah.io is the easy error logging and uptime monitoring service for .NET. Take back control of your errors with support for all .NET web and logging frameworks.
Start logging now
Free 21-day trial No credit card required