Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MicrosoftConsoleJsonLayout

Rolf Kristensen edited this page May 6, 2026 · 6 revisions

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

Platforms Supported: All - Requires nuget-package NLog.Extensions.Logging

Introduced with NLog.Extensions.Logging ver. 5.0

<target name="jsonFile" xsi:type="File" fileName="${logFileNamePrefix}.json" >
      <layout xsi:type="MicrosoftConsoleJsonLayout" includeScopes="Boolean" includeActivityIds="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.

  • IncludeActivityIds - Includes TraceId + SpanId + ParentId from System.Diagnostics.Activity.Current

    Introduced with NLog.Extensions.Logging ver. 6.1.3 - Simulates ActivityTrackingOptions.TraceId | ActivityTrackingOptions.SpanId | ActivityTrackingOptions.ParentId

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

  • IndentJson - Enables indent for JSON pretty format with newlines (From JsonLayout). Default = false

  • DottedRecursion - Flatten object-property-names (From JsonLayout). Default = false

    Introduced with NLog.Extensions.Logging ver. 6.1.1

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.