I'm trying to figure out how to stop NLog from replacing the Newlines in the strings I'm logging. I want the output to include all the line breaks and not place the entire output onto one line.
Can anybody help?
Config:
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="udp" xsi:type="NLogViewer" address="udp4://192.168.0.101:7071" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="udp" />
</rules>
</nlog>
Code:
var logger = LogManager.GetLogger($"Test");
var dumpStr = builder.ToString();
logger.Info(dumpStr);
The way the output looks is controlled by the layout. The message is formatted. You can tell it to output raw with a ${message:raw=true} declaration.
The default layout is:
${longdate}|${level:uppercase=true}|${logger}|${message}
So we would change that to:
${longdate}|${level:uppercase=true}|${logger}|${message:raw=true}
You would add this option to your target like so:
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="udp"
xsi:type="NLogViewer"
address="udp4://192.168.0.101:7071"
layout="${longdate}|${level:uppercase=true}|${logger}|${message:raw=true}"
/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="udp" />
</rules>
</nlog>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With