- Layouts are defining the layout of the rendered output, examples are a CSV, JSON, XML (NLog 4.6+) or plain layout (the default). There are currently 5 layouts in NLog (including the default): https://nlog-project.org/config/?tab=layouts
- Layout renderers are rendering values, e.g. a message, an exception, the process id etc. Also called "template markers". The layout renders looking as
${something}
. There are around 100 layout renderers in NLog, but there are also some 3rd party layout renderers. See https://nlog-project.org/config/?tab=layout-renderers
You can see a layout as a method to combine layout renderers. The default layout is a bit hidden, but other layouts should make it more clear. See the examples below.
Some examples:
Default layout
Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}"
This is the default layout with 4 layout renderers (date, level, message, exception)
JSON layout
A file target with a JsonLayout with the same 4 layout renderers:
<target name='jsonFile' type='File' fileName='log.json'>
<layout type='JsonLayout'>
<attribute name='time' layout='${longdate}' />
<attribute name='level' layout='${level:upperCase=true}'/>
<attribute name='message' layout='${message}' />
<attribute name='exception' layout='${exception}' />
</layout>
</target>
This will create file with e.g. { "time": "2016-10-30 13:30:55.0000", "level": "INFO", "message": "this is message", "exception": "test" }
The same for CSV, but then to create CSV files (or CSV to the database etc).
Exception layout renderer: ${exception}
(See also https://github.com/NLog/NLog/wiki/Exception-Layout-Renderer)
This is for rendering the exception, as exceptions are captured separate from the message in NLog. See also How to proper log exceptions