APM NLog Layoutedit

Allows you to add the following place holders in your NLog templates:

  • ElasticApmTraceId
  • ElasticApmTransactionId
  • ElasticApmSpanId
  • ElasticApmServiceName
  • ElasticApmServiceNodeName
  • ElasticApmServiceVersion

Which will be replaced with the appropriate Elastic APM variables if available


Add a reference to the Elastic.Apm.NLog package:

<PackageReference Include="Elastic.Apm.NLog" Version="8.6.0" />


How to use from APIedit

// Logged message will be in format of `trace-id|transation-id|span-id|InTransaction`
// or `|||InTransaction` if the place holders are not available
var consoleTarget = new ConsoleTarget("console");
consoleTarget.Layout =
config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget);
LogManager.Configuration = config;
var logger = LogManager.GetCurrentClassLogger();

How to use from NLog.configedit

    <add assembly="Elastic.Apm.NLog"/>
    <target name="console"
        layout="${ElasticApmTraceId}|${ElasticApmTransactionId}|${ElasticApmSpanId}|${message}" />
    <logger name="*" minLevel="Debug" writeTo="Console" />


The prerequisite for this to work is a configured Elastic APM Agent. If the agent is not configured the APM place holders will be empty.