Documentation
DocumentationDiscussions
Documentation
These docs are for v4. Click to read the latest docs for v2024.3.

Using NLog

Seq is a structured event server and works best with richly-structured event data like that produced by Serilog.

If you use NLog however, you're not left out; we provide an NLog target that writes events to Seq via HTTP. The Seq target for NLog even preserves format strings, so although you can't used named properties in your NLog messages for querying in Seq, the @0 and @1 placeholders can be used in queries to identify the parameters to {0} and {1} in format strings.

📘

NLog 4.5 adds structured logging support

NLog 4.5, currently in alpha, adds first-class structured logging with message templates. The setup instructions for using Seq with NLog 4.5 are different from the ones below - please see the linked article.

Installing the Target

At the time of writing, the Seq target for NLog supports .NET 4+.

At the Visual Studio Package Manager console, type:

PM> Install-Package Seq.Client.NLog

This will add the required assemblies to the project.

Then, add the target to your NLog configuration. You'll first need to add the Seq.Client.NLog assembly:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <extensions>
    <add assembly="Seq.Client.NLog"/>
  </extensions>

And then targets and rules entries:

<targets>
  <target name="seq" xsi:type="Seq" serverUrl="http://my-seq" />
</targets>
<rules>
  <logger name="*" minlevel="Info" writeTo="seq" />
</rules>

Set the serverUrl value to the address of your Seq server.

The Seq target supports buffering for better performance, if configured.

Writing Events

That's it! When you write log events to your NLog Logger:

logger.Info("Hello, {0}, from NLog!", Environment.UserName);

They'll appear beautifully in Seq, complete with queryable properties:

Enriching events with Layout Renderers

To add properties like thread ID or machine name typically provided by NLog Layout Renderers, use <property> elements in the target configuration:

<target name="seq" xsi:type="Seq" serverUrl="http://my-seq">
  <property name="SourceContext" value="${logger}" />
  <property name="ThreadId" value="${threadid}" as="number" />
  <property name="EnvironmentUserName" value="${windows-identity}" />
  <property name="MachineName" value="${machinename}" />
</target>

Any NLog layout expression can be used for the property value. Use as="number" to attempt numeric conversion of a value such as thread ID above.

Currently, all properties will be recorded as strings.