@@ -95,6 +95,28 @@ public static IDisposable CaptureScopeProperties(IReadOnlyList<KeyValuePair<stri
9595 object scopeObject = scopePropertyList ;
9696
9797 if ( scopePropertyList . Count > 0 && NLogLogger . OriginalFormatPropertyName . Equals ( scopePropertyList [ scopePropertyList . Count - 1 ] . Key ) )
98+ {
99+ scopePropertyList = ExcludeOriginalFormatProperty ( scopePropertyList ) ;
100+ }
101+
102+ return CreateScopeProperties ( scopeObject , scopePropertyList ) ;
103+ }
104+
105+ private static IReadOnlyList < KeyValuePair < string , object > > ExcludeOriginalFormatProperty ( IReadOnlyList < KeyValuePair < string , object > > scopePropertyList )
106+ {
107+ if ( scopePropertyList . Count == 2 && ! NLogLogger . OriginalFormatPropertyName . Equals ( scopePropertyList [ 0 ] . Key ) )
108+ {
109+ scopePropertyList = new [ ] { scopePropertyList [ 0 ] } ;
110+ }
111+ else if ( scopePropertyList . Count <= 2 )
112+ {
113+ #if NET451
114+ scopePropertyList = new KeyValuePair < string , object > [ 0 ] ;
115+ #else
116+ scopePropertyList = Array . Empty < KeyValuePair < string , object > > ( ) ;
117+ #endif
118+ }
119+ else
98120 {
99121 var propertyList = new List < KeyValuePair < string , object > > ( scopePropertyList . Count - 1 ) ;
100122 for ( var i = 0 ; i < scopePropertyList . Count ; ++ i )
@@ -110,7 +132,7 @@ public static IDisposable CaptureScopeProperties(IReadOnlyList<KeyValuePair<stri
110132 scopePropertyList = propertyList ;
111133 }
112134
113- return CreateScopeProperties ( scopeObject , scopePropertyList ) ;
135+ return scopePropertyList ;
114136 }
115137
116138 public static IDisposable CaptureScopeProperties ( IEnumerable scopePropertyCollection , ExtractorDictionary stateExtractor )
0 commit comments