Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I log the CorrelationManager.ActivityId with NLog

How can I log the CorrelationManager.ActivityId as a separate field?

Here is my current NLog.config:

<?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">

  <variable name="logDirectory" value="${basedir}/Logs" />

  <extensions>
    <add assembly="NLog.Mongo"/>
  </extensions>

  <targets>
    <target xsi:type="Mongo"
            name="mongoCustom"
            includeDefaults="false"
            connectionString="mongodb://localhost/FooLogging"
            collectionName="authLogs">

      <field name="Date" layout="${longdate:universalTime=true}" />
      <field name="Level" layout="${level}"/>
      <field name="Message" layout="${message}" />
      <field name="Logger" layout="${logger}"/>
      <field name="Exception" layout="${exception:format=tostring}" />
      <field name="ThreadID" layout="${threadid}" />
      <field name="ThreadName" layout="${threadname}" />
      <field name="ProcessID" layout="${processid}" />
      <field name="ProcessName" layout="${processname:fullName=true}" />
      <field name="UserName" layout="${windows-identity}" />
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="mongoCustom" />
  </rules>
</nlog>
like image 607
tugberk Avatar asked Apr 26 '14 16:04

tugberk


1 Answers

${activityid} was added in NLog v4.1. https://github.com/nlog/nlog/wiki/Trace-Activity-Id-Layout-Renderer

like image 89
Dav Evans Avatar answered Sep 25 '22 20:09

Dav Evans