Start your 14-day free trial today & Get 20% Off All Annual Managed ELK Plans

No Credit Card Required

Try Logit.io Free

Already 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 or .NET Core application to logstash

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

Step 1 - InstallCopy

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 NLogCopy

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 NLogCopy

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

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();

            try
            {
                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", "127.0.0.1");
                System.Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(".NET Core NLog Logger app failed...");
                Console.WriteLine(ex.Message);
                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 - 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