- Notifications
You must be signed in to change notification settings - Fork1.4k
SimpleLayout
Represents a string with embedded placeholders that can render contextual information from the LogEvent.
Platforms Supported:All
SimpleLayout is used by default when nothing specified, so one can just write:
<targets> <targetlayout="Hello ${message}" /></targets>
But one can explictly specify theSimpleLayout-type like this:
<targets> <target> <layoutxsi:type="SimpleLayout"text="Hello ${message}" /> </target></targets>
- text - Layout text
The layout is not meant to be built explicitly from code, instead assign a string, e.g.Layout l = "${longdate}|${level}|${logger}|${message}"
The layout can be literal text like"Hello", but can also contain Layout-Renderers like${message}. See also:List of Layout-Renderers
Many NLog Targets has theirLayout-option configured to this default-value:
${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}
NLog Layout-format recognizes the colon-character: as option-delimiter, but only when used inside${ and}. To avoid unexpected results, then one can escape using back-slash like this:\:. Ex.${date:format=HH\:mm\:ss}
There also exists Layout-types for more structured output-formats likeJSON,XML,CSV, etc. See also:List of Layouts
-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