Skip to content

MicrosoftConsoleJsonLayout

Rolf Kristensen edited this page Oct 8, 2022 · 2 revisions

A custom NLog JsonLayout that renders to JSON to simulate Microsoft Logging AddJsonConsole.

Platforms Supported: All

Introduced with NLog.Extensions.Logging ver. 5.0

<target name="jsonFile" xsi:type="File" fileName="${logFileNamePrefix}.json" >
      <layout xsi:type="MicrosoftConsoleJsonLayout" includeScopes="Boolean">
         <attribute name="extraPropertyName" layout="extraPropertyValue" />
         <state name="extraStateName" layout="extraStateValue" />
      </layout>
</target>

This would write:

{ "Timestamp": "2010-01-01 12:34:56.0000Z", "EventId": 110, "LogLevel": "Debug", "Category": "ConsoleApp.Program", "message": "hello, world", "State": { "location:" "world", "{OriginalFormat}": "hello, {location}" } }

Parameters

  • Attribute - Additional attributes.

  • State - Additional state attributes, besides the message properties.

  • IncludeScopes - Include ScopeContext Nested states as additional Scopes-attribute.

  • TimestampFormat - Override the format of the UTC Timestamp. Default = "O"

Clone this wiki locally