Help Docs

NLog Logs

NLog is a widely used logging framework in windows .NET Application and C#. Site24x7 AppLogs is a one of a kind cloud based log management service that helps you manage logs with ease. Site24x7 agent automatically detects NLog based logs in your machine and identifies the log fields such as date & time, log level, logger name, and message. With default support for NLog logs, you can search, view, collect and analyze the data with the help of the intuitive web client.  Learn more about log management with Site24x7.

You can push your NLogs using either of the below methods:

With agent 

  1. Log in to your Site24x7 account.
  2. Download and install the Site24x7 Server Monitoring agent (Windows). 
  3. Go to Admin > AppLogs > Log Profile and Add Log Profile.
  4. Select NLog from Choose the Log Type.
  5. NLog logs are sourced from the below-mentioned folder path. If you have logs in a different folder, you can mention them under the List of files to search for logs to source them from that folder while creating a log profile.
    C:\\NLog\\.log
    Log file path given here is for reference ONLY. By default, Site24x7 runs a script to find the specific file path.
  6. Select the server monitor to collect the logs and then save the profile.

Without agent

  1. Log in to your Site24x7 account.
  2. Go to Admin > AppLogs > Log Type and Add Log Type.
  3. Choose NLog from Choose the Log Type.
  4. Enable API Upload.
  5. Copy the HTTPS endpoint URL.
  6. Click Save.
  7. Download the below NLog configuration  XML file and update your application. Replace the '<ENDPOINT-URL>' with the URL available copied in step 5 above.
    <?xml version="1.0" encoding="utf-8" ?>
    <nlog
     xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          throwConfigExceptions="true"
          internalLogLevel="Off"
          internalLogToConsole="false"
          internalLogFile="C:\home\LogFiles\nlog-internal-logs.txt"
    >
     <extensions>
     <add assembly="NLog.Targets.Http" />
     </extensions>
     <targets>
     <target name='site24x7-logs' 
                type='HTTP' 
                URL='<ENDPOINT-URL>'
                BatchSize='100'
                ContentType='application/json'
        >
    <layout type='JsonLayout'>
     <attribute name='loglevel' layout='${level:upperCase=true}' />
     <attribute name='message' layout='${message}' />
     <attribute name='datetime' layout='${longdate}' />
     <attribute name='_zl_timestamp' layout='${replace:inner=${unixtime:universalTime=true}:searchFor=.:replaceWith=}' /> 
     <attribute name='s247agentuid' layout='logsource' />
     </layout>
     </target>
     </targets>
     <rules>
     <logger name="*" minlevel="Debug" writeTo="site24x7-logs" />
     </rules>
    </nlog>
  8. Install the "NLog.Targets.Http" package in NLog, if unavailable. Site24x7 uses this package in NLog to batch the log messages and upload them to our server.

Log pattern

$DateTime:date$ $LogLevel$ $SourceFileName$ $Line:number$ - $Message$

This is the default pattern defined by Site24x7 for parsing NLog logs based on the sample log mentioned below.

Sample log

2017-07-02 20:52:39,342 DEBUG className 200 - This is debug message

The above sample log can be separated into 4 fields, each of which will take its respective value from here and will then be uploaded to Site24x7.

 Field name  Field value
DateTime 2017-07-02 20:52:39,342
LogLevel DEBUG
SourceFileName className
Line 200
Message This is debug message   

Related log types

Was this document helpful?

Shortlink has been copied!