-
Notifications
You must be signed in to change notification settings - Fork 1.4k
CompoundLayout
Rolf Kristensen edited this page Dec 27, 2023
·
3 revisions
Concatenate multiple layouts, so they become a single layout.
Platforms Supported: All
Introduced in NLog 4.3.6
<target name='file' type='File' fileName='log.txt'>
<layout type='CompoundLayout'>
<layout type='SimpleLayout' text="text1" />
<layout type='SimpleLayout' text=" - " />
<layout type='SimpleLayout' text="text2" />
</layout>
</target>
text1 - text2
var compoundLayout = new CompoundLayout
{
Layouts =
{
new SimpleLayout("myAmazingText: "),
new JsonLayout
{
Attributes =
{
new JsonAttribute("time", "${longdate}"),
new JsonAttribute("level", "${level:upperCase=true}"),
}
}
}
};
myAmazingText: { "time": "2016-10-30 13:30:55.0000", "level": "INFO" }
<nlog>
<targets>
<target name='file' type='File' fileName='log.txt'>
<layout type='CompoundLayout'>
<layout type='SimpleLayout' text="myAmazingText: " />
<layout type='JsonLayout'>
<attribute name='time' layout='${longdate}' />
<attribute name='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
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json