@@ -15,7 +15,7 @@ namespace NLog.Extensions.Logging
1515 [ ThreadAgnostic ]
1616 public class MicrosoftConsoleJsonLayout : JsonLayout
1717 {
18- private static readonly string [ ] EventIdMapper = Enumerable . Range ( 0 , 50 ) . Select ( id => id . ToString ( System . Globalization . CultureInfo . InvariantCulture ) ) . ToArray ( ) ;
18+ private static readonly string [ ] EventIdMapper = Enumerable . Range ( 0 , 512 ) . Select ( id => id . ToString ( System . Globalization . CultureInfo . InvariantCulture ) ) . ToArray ( ) ;
1919
2020 private readonly SimpleLayout _timestampLayout = new SimpleLayout ( "\" ${date:format=o:universalTime=true}\" " ) ;
2121
@@ -47,7 +47,7 @@ public IList<JsonAttribute>? StateAttributes
4747 get
4848 {
4949 var index = LookupNamedAttributeIndex ( "State" ) ;
50- return index >= 0 ? ( Attributes [ index ] ? . Layout as JsonLayout ) ? . Attributes : null ;
50+ return index >= 0 ? ( Attributes [ index ] ? . Layout as JsonLayout ) ? . Attributes : new List < JsonAttribute > ( ) ;
5151 }
5252 }
5353
@@ -99,6 +99,31 @@ public string? TimestampFormat
9999 }
100100 }
101101
102+ /// <inheritdoc />
103+ protected override void InitializeLayout ( )
104+ {
105+ IncludeEventProperties = false ;
106+ IncludeScopeProperties = false ;
107+
108+ var stateIndex = LookupNamedAttributeIndex ( "State" ) ;
109+ var stateJsonLayout = stateIndex >= 0 ? Attributes [ stateIndex ] ? . Layout as JsonLayout : null ;
110+ if ( stateJsonLayout != null )
111+ {
112+ stateJsonLayout . MaxRecursionLimit = MaxRecursionLimit ;
113+ stateJsonLayout . ExcludeEmptyProperties = ExcludeEmptyProperties ;
114+ stateJsonLayout . SuppressSpaces = SuppressSpaces && ! IndentJson ;
115+ if ( ExcludeProperties ? . Count > 0 )
116+ {
117+ foreach ( var excludeProperty in ExcludeProperties )
118+ {
119+ stateJsonLayout . ExcludeProperties . Add ( excludeProperty ) ;
120+ }
121+ }
122+ }
123+
124+ base . InitializeLayout ( ) ;
125+ }
126+
102127 private int LookupNamedAttributeIndex ( string attributeName )
103128 {
104129 for ( int i = 0 ; i < Attributes . Count ; ++ i )
0 commit comments