APM NLog Layout
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
APM NLog Layout
editAllows 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
Installation
editAdd a reference to the Elastic.Apm.NLog package:
<PackageReference Include="Elastic.Apm.NLog" Version="8.6.0" />
Usage
editHow to use from API
edit// 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 =
"${ElasticApmServiceName}|${ElasticApmTraceId}|${ElasticApmTransactionId}|${ElasticApmSpanId}|${message}";
config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget);
LogManager.Configuration = config;
var logger = LogManager.GetCurrentClassLogger();
How to use from NLog.config
edit<nlog>
<extensions>
<add assembly="Elastic.Apm.NLog"/>
</extensions>
<targets>
<target name="console"
type="console"
layout="${ElasticApmTraceId}|${ElasticApmTransactionId}|${ElasticApmSpanId}|${message}" />
</targets>
<rules>
<logger name="*" minLevel="Debug" writeTo="Console" />
</rules>
</nlog>
Prerequisite
editThe prerequisite for this to work is a configured Elastic APM Agent. If the agent is not configured the APM place holders will be empty.