I'm using NLog to log in json format, using the targets below (file and network).
When logging to the file target or both file and network, the messages are logged fine.
However, when using only the network target, dbResponseTime and messagesSentTotal will not be included in the message (in fact, any attribute using a layout with "event-properties:item="). All the other properties are present, including the one defined in the end (module).
<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false" internalLogLevel="Off">
<targets>
<target name="logHealthCheck" xsi:type="File"
fileName="D:\Logs\HealthCheck.${shortdate}.json"
archiveFileName="D:\Logs\HealthCheck.{#}.json"
archiveNumbering="DateAndSequence"
archiveAboveSize="33554432"
archiveDateFormat="yyyy-MM-dd">
<layout xsi:type="JsonLayout">
<attribute name="timestamp" layout="${date:universalTime=true:format=o}" />
<attribute name="machineName" layout="${machinename}" />
<attribute name="environment" layout="${literal:text=DEV}" />
<attribute name="dbResponseTime" layout="${event-properties:item=dbResponseTime}" encode="false"/>
<attribute name="messagesSentTotal" layout="${event-properties:item=messagesSentTotal}" encode="false"/>
<attribute name="module" layout="${literal:text=core}" />
</layout>
</target>
<target name="logHealthCheckNetwork" xsi:type="Network" address="tcp://127.0.0.1:1514" newLine="true">
<layout xsi:type="JsonLayout">
<attribute name="timestamp" layout="${date:universalTime=true:format=o}" />
<attribute name="machineName" layout="${machinename}" />
<attribute name="environment" layout="${literal:text=DEV}" />
<attribute name="dbResponseTime" layout="${event-properties:item=dbResponseTime}" encode="false"/>
<attribute name="messagesSentTotal" layout="${event-properties:item=messagesSentTotal}" encode="false"/>
<attribute name="module" layout="${literal:text=core}" />
</layout>
</target>
<rules>
<logger name="HealthCheck" minlevel="Debug" writeTo="logHealthCheck,logHealthCheckNetwork">
<filters>
</filters>
</logger>
</rules>
</nlog>
Switched on the internal log, and no error is recorded. Trace below:
2018-02-02 16:43:07.7837 Trace Scanning LoggingRule 'logNamePattern: (HealthCheck:Equals) levels: [ Debug Info Warn Error Fatal ] appendTo: [ logHealthCheckNetwork ]'
2018-02-02 16:43:07.7993 Trace Scanning NetworkTarget 'Network Target[logHealthCheckNetwork]'
2018-02-02 16:43:07.8305 Trace Scanning SimpleLayout ''tcp://127.0.0.1:1514''
2018-02-02 16:43:07.8305 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2018-02-02 16:43:07.9085 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:07.9085 Trace Scanning SimpleLayout ''${date:universalTime=true:format=o}''
2018-02-02 16:43:07.9241 Trace Scanning DateLayoutRenderer 'Layout Renderer: ${date}'
2018-02-02 16:43:07.9397 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:07.9397 Trace Scanning SimpleLayout ''${machinename}''
2018-02-02 16:43:07.9553 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2018-02-02 16:43:07.9553 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:07.9709 Trace Scanning SimpleLayout ''${literal:text=DEV}''
2018-02-02 16:43:07.9709 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2018-02-02 16:43:08.0177 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:08.0333 Trace Scanning SimpleLayout ''${event-properties:item=dbResponseTime}''
2018-02-02 16:43:08.0333 Trace Scanning EventPropertiesLayoutRenderer 'Layout Renderer: ${event-properties}'
2018-02-02 16:43:08.0801 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:08.0801 Trace Scanning SimpleLayout ''${event-properties:item=messagesSentTotal}''
2018-02-02 16:43:08.3453 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:08.3609 Trace Scanning SimpleLayout ''${literal:text=core}''
2018-02-02 16:43:08.3765 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'