I have .Net project with NLog configuration which allows me to produce JSON-formatted log file. It works fine with simple text messages. Now, I need to log a number of arbitrary objects already serialized to JSON. When I log those JSON strings as log messages, NLog puts the text in quotes and subsequently escapes inner JSON syntax. This renders such output unusable. So far I have failed to find an NLog feature or layout setting that would simply dump my JSON string as a literal, without quotation marks and escape characters. Am I missing something?
Example. Currently my log entries look like:]
{ "dateTime": "2017-06-07 11:50:55.7324", "level": "DEBUG", "message": "\"description\": \"blah-blah\", \"Request\": { \"Request URL\":\/somepagepage\/}, \"Content\": { \"Form\": { ... } , \"Body\": \"Blah\" } ", "utcDateTime": "2017-06-05 06:10:34.1411" }
Instead, I need to make them to look like:
{ "dateTime": "2017-06-07 11:50:55.7324", "level": "DEBUG", "message":
{ "description": "blah-blah", "Request": { "Request URL":/somepagepage/, "Content": { "Form": {...}, "Body": "Blah" } }, "utcDateTime": "2017-06-05 06:10:34.1411" }
Relevant section from NLog.config:
<layout xsi:type="JsonLayout">
<attribute name="dateTime" layout="${longdate}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="message" layout="${message}" />
<attribute name="utcDateTime" layout="${longdate:universalTime=true}" />
</layout>
Ultimately, I would like to see a log entry with JSON nested inside "message", and not a quoted version of it.