Get a DemoStart Free TrialSign In

Nlog Logstash Setup

Ship logs from your .NET or .NET Core application to logstash

Use the NLog configuration examples below to ship logs from your .NET or .NET Core application to Logstash

Follow this step by step guide to get 'logs' from your system to

Step 1 - Install

This guide assumes that Visual Studio 2019 is being used as the IDE (Integrated Development Environment). Type the relevant command below into the NuGet Package Manager console (you can find it under the Tools menu -> NuGet Package Manager -> Package Manager Console). If you are using a different IDE please consult the NLog wiki for guidance.

For .NET:

Install-Package NLog

For .NET Core:

Install-Package NLog.Web.AspNetCore

This will install the latest version. If you want to install a particular version you should append the version number you want to install, for example, for .NET:

Install-Package NLog -Version 4.7.10

For .NET Core:

Install-Package NLog.Web.AspNetCore -Version 4.12.0

For further information check out the NLog documentation

Step 2 - Configuring NLog

Configuring NLog can be done in your application app.config, web.config or a separate nlog.config file.

For further information check out the NLog documentation

Step 3 - Using NLog

In order to emit log message you can simply call one of the methods on the Logger. This is an example in .NET 4:

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", "");

This is an example in .NET Core:

using System;

namespace NlogTestAppCore
    class Program
        public static void Main()
            var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

                Console.WriteLine(".NET Core NLog Logger app started...");
                logger.Info("Hello world");
                //below is an example of structured logging 
                logger.Info(".NET Core Nlog example App started by {user} from {ip_address}", 
                  "GreatestUser", "");
            catch (Exception ex)
                Console.WriteLine(".NET Core NLog Logger app failed...");
                logger.Error(ex, "Goodbye cruel world");

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 - Check for your logs

Data should now have been sent to your Stack.

View my data

If you don't see logs take a look at How to diagnose no data in Stack below for how to diagnose common issues.

Step 5 - how to diagnose no data in Stack

If you don't see data appearing in your Stack after following the steps, visit the Help Centre guide for steps to diagnose no data appearing in your Stack or Chat to support now.

Step 6 - NLog Logger Overview

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.

Return to Search
Sign Up

© 2024 Ltd, All rights reserved.