Skip to content

Can the message itself be a json object? #2895

@sheepinwild

Description

@sheepinwild

My config looks like this. However sometimes the ${message} itself is a json object and when it is outputted, all the double quotes get escaped by the backslash. Is there a way to output the json message just like a json string? I'm using the package NLog.Web.AspNetCore.

 <target name="fileTarget" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
      <target xsi:type="File" fileName="${logDirectory}/dotnetapp.log"
              archiveFileName="${logDirectory}/archives/{#}.log"
              archiveEvery="Day" archiveNumbering="Date" maxArchiveFiles="4">
        <layout xsi:type="JsonLayout">
          <attribute name="date" layout="${longdate}" />
          <attribute name="log-level" layout="${level:uppercase=true}" />
          <attribute name="logger" layout="${logger}" />
          <attribute name="trace-id" layout="${aspnet-Traceidentifier}" />
          <attribute name="message" encode="false">
            <layout xsi:type="JsonLayout">
              <attribute name="body" escapeUnicode="false" layout="${message}" />
              <attribute name="ex" layout="${exception:format=tostring}" />
            </layout>
          </attribute>
        </layout>
      </target>
    </target>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions