Ready to get going? Start your 14 days free trial today

Start free trial

Have an account? Sign in

Send data via NLog to your Logstash instance provided by Logit.io

Nlog Logstash Setup

Ship logs from your .NET application to logstash

Use the Logit.io NLog configuration example below to ship logs from your .NET application to Logstash

Step 1 - InstallCopy

Installing NLog Install NLog from Nuget. For .NET:

Install-Package NLog

For .NET Core:

Install-Package NLog.Web.AspNetCore

Step 2 - Configuring NLogCopy

Configuring NLog can be done in your application app.config or web.config.

<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
  </configSections>
  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
    <targets>
      <target
        xsi:type="Network"
        name="LogitTarget"
        address="tcp://your-logstash-host:your-port"
        newLine="True">
        <layout type="JsonLayout" includeAllProperties="true">
          <attribute name="timestamp" layout="${longdate}" />
          <attribute name="logger" layout="${logger}" />
          <attribute name="machinename" layout="${machinename}" />
          <attribute name="threadid" layout="${threadid}" />
          <attribute name="level" layout="${level}"/>
          <attribute name="message" layout="${message}" />
          <attribute name="exception" layout="${exception}" />
        </layout>
      </target>
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="LogitTarget" />
    </rules>
  </nlog>
</configuration>

Step 3 - Using NLogCopy

In order to emit log message you can simply call one of the methods on the Logger.

using NLog;

public class MyClass
{
  private static Logger logger = LogManager.GetCurrentClassLogger();

  public void MyMethod1()
  {
    logger.Info("Sample trace message");
    //below is an example of structured logging 
    logger.Info("Logon by {user} from {ip_address}", "GreatestUser", "127.0.0.1");
  }
}

NLog is a fully featured logging platform for .NET developers that provides many quality of life benefits. For more configuration options please see the Nlog Documentation. For more information about structured logging please see here and here for a comprehensive tutorial about setting up and using NLog.

Step 4 - NLog Logger OverviewCopy

NLog is a free open source logging platform for .NET & .NET Core, that is often compared to Serilog & Log4net. NLog is well known for being easy to use & is highly flexible alongside its high performance capabilities.

NLog also provides support for structured log data & covers a huge range of data targets and formats. NLog is able to note a variety of log severities including (by descending priority); Fatal, Error, Warn, Info, Debug & Trace.

While NLog itself is a logging platform, the service also creates internal application logs of its own that many users find extremely hard to troubleshoot & parse without the use of a tool like Hosted Logstash.

Our platform offers Hosted Logstash alongside Elasticsearch & Kibana to help you view the entirety of your Nlog & .Net log files (among hundreds of other popular data sources) in a single source of truth.

If after following our NLog documentation you require any additional assistance with analysing your NLog or .Net logs we're here to help. Just reach out by contacting our support team via live chat & we'll be happy to help you get started.

Toggle View

Expand View

Return to Search