Our next-gen architecture is built to help you make sense of your ever-growing data Watch a 4-min demo video!

Back to All Integrations

NLog NLog

Last Updated: Mar. 30, 2022

NLog Implementation tutorial: 

To install Coralogix.NLog, run the following command in the Package Manager Console 

Install-Package Coralogix.NLog

For .NET Core, use: 

Install-Package CoralogixCoreNLog

General

Private Key– A unique ID that represents your company. The private key can be found under ‘settings’->’ send your logs’. It is located in the upper left corner.

Application Name – The name of your main application, for example, a company called “SuperData” would probably insert the “SuperData” string parameter or if they want to debug their test environment they might insert the “SuperData– Test”.

SubSystem Name – Your application probably has multiple subsystems, for example, Backend servers, Middleware, Frontend servers, etc. to help you examine the data you need, inserting the subsystem parameter is vital.

Via NLOG configuration XML:

<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <extensions>
    <add assembly="CoralogixNLog"/>
  </extensions>
  <targets>
    <target name="console" xsi:type="CoralogixNLog"
            PrivateKey="9626c7dd-8174-5015-a3fe-5572e042b6d9"
            ApplicationName="MyTestApp"
            SubsystemName="BL"
            layout="${date:format=HH\:MM\:ss} ${logger} ${message}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Info" writeTo="console" />
  </rules>
</nlog>

Via code:

LoggingConfiguration config = new LoggingConfiguration();


            CoralogixTarget coralogixTarget = new CoralogixTarget();
            config.AddTarget("Coralogix", coralogixTarget);

            //Configure the Croalogix target with the Coralogix settings.
            //You need to configure this only once.
            coralogixTarget.PrivateKey = "9626c7dd-8174-5015-a3fe-5572e042b6d9";
            coralogixTarget.ApplicationName = "MyTestApp";
            coralogixTarget.SubsystemName = "BL";


            coralogixTarget.Layout = @"${date:format=HH\:mm\:ss} ${logger} ${message}";

            //Configure the Level filter for the Coralogix Target 
            var rule1 = new LoggingRule("*", NLog.LogLevel.Debug, coralogixTarget);
            config.LoggingRules.Add(rule1);

            // Define the actual NLog logger which through it all log entires should be reported
            NLog.LogManager.Configuration = config;


            // The common practice is to get an instance of the logger in each class and setting the logger name to the class name.
            //logger name will be used as category unless specified otherwise.
            NLog.Logger nlogger = NLog.LogManager.GetLogger("MyApp");


            nlogger.Debug("Hello world");
            nlogger.Info("Hello world");
            nlogger.Warn("Hello world");
            nlogger.Error("Hello world");
            nlogger.Trace("Hello world");

Need help? We love to assist our customers, simply reach out via the in-app chat, and we will walk you through, step by step.

On this page