@@ -55,39 +55,35 @@ public void EnrichAndCreateScopeItem(LogEvent logEvent, ILogEventPropertyFactory
55
55
return ;
56
56
}
57
57
58
- // Eliminates boxing of Dictionary<TKey, TValue>.Enumerator for the most common use case
59
58
if ( _state is Dictionary < string , object > dictionary )
60
59
{
61
- scopeItem = null ; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items .
62
-
60
+ // Separate handling of this case eliminates boxing of Dictionary<TKey, TValue>.Enumerator .
61
+ scopeItem = null ;
63
62
foreach ( var stateProperty in dictionary )
64
63
{
65
- if ( stateProperty . Key == SerilogLoggerProvider . OriginalFormatPropertyName && stateProperty . Value is string )
66
- scopeItem = new ScalarValue ( _state . ToString ( ) ) ;
67
- else
68
- AddProperty ( logEvent , propertyFactory , stateProperty . Key , stateProperty . Value ) ;
64
+ AddProperty ( logEvent , propertyFactory , stateProperty . Key , stateProperty . Value ) ;
69
65
}
70
66
}
71
67
else if ( _state is IEnumerable < KeyValuePair < string , object > > stateProperties )
72
68
{
73
- scopeItem = null ; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items.
74
-
69
+ scopeItem = null ;
75
70
foreach ( var stateProperty in stateProperties )
76
71
{
77
- if ( stateProperty . Key == SerilogLoggerProvider . OriginalFormatPropertyName && stateProperty . Value is string )
72
+ if ( stateProperty is { Key : SerilogLoggerProvider . OriginalFormatPropertyName , Value : string } )
73
+ {
74
+ // `_state` is most likely `FormattedLogValues` (a MEL internal type).
78
75
scopeItem = new ScalarValue ( _state . ToString ( ) ) ;
76
+ }
79
77
else
78
+ {
80
79
AddProperty ( logEvent , propertyFactory , stateProperty . Key , stateProperty . Value ) ;
80
+ }
81
81
}
82
82
}
83
83
else if ( _state is ValueTuple < string , object ? > tuple )
84
84
{
85
- scopeItem = null ; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items.
86
-
87
- if ( tuple . Item1 == SerilogLoggerProvider . OriginalFormatPropertyName && tuple . Item2 is string )
88
- scopeItem = new ScalarValue ( _state . ToString ( ) ) ;
89
- else
90
- AddProperty ( logEvent , propertyFactory , tuple . Item1 , tuple . Item2 ) ;
85
+ scopeItem = null ;
86
+ AddProperty ( logEvent , propertyFactory , tuple . Item1 , tuple . Item2 ) ;
91
87
}
92
88
else
93
89
{
0 commit comments