- Notifications
You must be signed in to change notification settings - Fork1.4k
CompoundLayout
Rolf Kristensen edited this pageDec 27, 2023 ·3 revisions
Concatenate multiple layouts, so they become a single layout.
Platforms Supported:All
Introduced in NLog 4.3.6
<targetname='file'type='File'fileName='log.txt'> <layouttype='CompoundLayout'> <layouttype='SimpleLayout'text="text1" /> <layouttype='SimpleLayout'text=" -" /> <layouttype='SimpleLayout'text="text2" /> </layout></target>
text1 - text2varcompoundLayout=newCompoundLayout{Layouts={newSimpleLayout("myAmazingText: "),newJsonLayout{Attributes={newJsonAttribute("time","${longdate}"),newJsonAttribute("level","${level:upperCase=true}"),}}}};
myAmazingText: { "time": "2016-10-30 13:30:55.0000", "level": "INFO" }<nlog> <targets> <targetname='file'type='File'fileName='log.txt'> <layouttype='CompoundLayout'> <layouttype='SimpleLayout'text="myAmazingText:" /> <layouttype='JsonLayout'> <attributename='time'layout='${longdate}' /> <attributename='level'layout='${level:upperCase=true}'/> </layout> </layout> </target> </targets> <rules> </rules></nlog>
myAmazingText: { "time": "2016-10-30 13:30:55.0000", "level": "INFO" }-Troubleshooting Guide - See available NLog Targets and Layouts:https://nlog-project.org/config
- All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json