Reputation: 975
In my NLog Config I have a variable to hold my JsonLayout:
<variable name="jsonLayoutv0.1">
<layout type="JsonLayout">
<attribute name="time" layout="${longdate}" />
</layout>
</variable>
I then want to place this layout inside a compoundLayout later on in my NLog config without having to re-write the whole jsonLayout again:
<sl:layout xsi:type="CompoundLayout">
<layout xsi:type="SimpleLayout" text="@cee: " />
<INSERT HERE/>
</sl:layout>
How can I go about re-using the variable inside a CompoundLayout?
Upvotes: 0
Views: 1191
Reputation: 19867
NLog 5.0.1 is now available: https://www.nuget.org/packages/NLog/5.0.1 so you can do this:
<nlog>
<variable name='jsonLayoutv0.1'>
<layout type='JsonLayout'>
<attribute name='short_date' layout='${shortdate}' />
<attribute name='message' layout='${message}' />
</layout>
</variable>
<targets>
<target name='compoundFile' type='File' fileName='log.txt'>
<layout type='CompoundLayout'>
<layout type='SimpleLayout' text='|Before| ' />
<layout type='${jsonLayoutv0.1}' />
<layout type='SimpleLayout' text=' |After|' />
</layout>
</target>
</nlog>
See also: https://github.com/NLog/NLog/pull/4940
Upvotes: 1