Skip to main content
NLog

An appender to your NLOG logger for an easy integration with Coralogix

Zvika Kozniak avatar
Written by Zvika Kozniak
Updated over a year ago

NLog Implementation tutorial: 

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

PM> Install-Package Coralogix.NLog

General :

Private Key – A unique ID which represents your company, this Id will be sent to your mail once you register to Coralogix.

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="your-private-key"
            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 = "your-private-key";             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");

Did this answer your question?