Before you begin, review the Supported Log Frameworks.

For log4net, the following metadata is added to the relevant global or the current scope context and written to the log file.

  • appd_node_id
  • appd_bt_id
  • appd_request_guid

This is an example of log4net log enrichment using an appender.

log4net

<log4net>
    <appender name="RollingFile" type="log4net.Appender.FileAppender">
        <file value="app.log" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] appd_node_id=%property{appd_node_id} appd_bt_id=%property{appd_bt_id} appd_request_guid=%property{appd_request_guid} %-5level %logger{1} %message%newline" />
        </layout>
    </appender>
    <root>
        <level value="ALL" />
        <appender-ref ref="RollingFile" />
    </root>
</log4net>
XML


For NLogs, the following metadata is injected into the log files.

  • Global scope context
    • appd_node_id
  • Current scope context
    • appd_bt_id
    • appd_request_guid 

This is an example of NLog configuration settings that utilize targets to inject metadata into log files.

NLog

<targets>
    <!-- File Target for all log messages with basic details -->
    <target xsi:type="File" name="allfile" fileName=".\nlog-AspNetCore-all-${shortdate}.log" layout="${longdate}|appd_node_id=${gdc:appd_node_id}|appd_bt_id=${scopeproperty:appd_bt_id}|appd_request_guid=${scopeproperty:appd_request_guid}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" />
</targets>
XML