@@ -47,7 +47,9 @@ public void Dispose()
47
47
}
48
48
}
49
49
50
- public void EnrichAndCreateScopeItem ( LogEvent logEvent , ILogEventPropertyFactory propertyFactory , out LogEventPropertyValue ? scopeItem )
50
+ public void EnrichAndCreateScopeItem ( LogEvent logEvent , ILogEventPropertyFactory propertyFactory , out LogEventPropertyValue ? scopeItem ) => EnrichWithStateAndCreateScopeItem ( logEvent , propertyFactory , _state , out scopeItem ) ;
51
+
52
+ public static void EnrichWithStateAndCreateScopeItem ( LogEvent logEvent , ILogEventPropertyFactory propertyFactory , object ? state , out LogEventPropertyValue ? scopeItem )
51
53
{
52
54
void AddProperty ( string key , object ? value )
53
55
{
@@ -68,61 +70,61 @@ void AddProperty(string key, object? value)
68
70
logEvent . AddPropertyIfAbsent ( property ) ;
69
71
}
70
72
71
- if ( _state == null )
73
+ if ( state == null )
72
74
{
73
75
scopeItem = null ;
74
76
return ;
75
77
}
76
78
77
79
// Eliminates boxing of Dictionary<TKey, TValue>.Enumerator for the most common use case
78
- if ( _state is Dictionary < string , object > dictionary )
80
+ if ( state is Dictionary < string , object > dictionary )
79
81
{
80
82
scopeItem = null ; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items.
81
83
82
84
foreach ( var stateProperty in dictionary )
83
85
{
84
86
if ( stateProperty . Key == SerilogLoggerProvider . OriginalFormatPropertyName && stateProperty . Value is string )
85
- scopeItem = new ScalarValue ( _state . ToString ( ) ) ;
87
+ scopeItem = new ScalarValue ( state . ToString ( ) ) ;
86
88
else
87
89
AddProperty ( stateProperty . Key , stateProperty . Value ) ;
88
90
}
89
91
}
90
- else if ( _state is IEnumerable < KeyValuePair < string , object > > stateProperties )
92
+ else if ( state is IEnumerable < KeyValuePair < string , object > > stateProperties )
91
93
{
92
94
scopeItem = null ; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items.
93
95
94
96
foreach ( var stateProperty in stateProperties )
95
97
{
96
98
if ( stateProperty . Key == SerilogLoggerProvider . OriginalFormatPropertyName && stateProperty . Value is string )
97
- scopeItem = new ScalarValue ( _state . ToString ( ) ) ;
99
+ scopeItem = new ScalarValue ( state . ToString ( ) ) ;
98
100
else
99
101
AddProperty ( stateProperty . Key , stateProperty . Value ) ;
100
102
}
101
103
}
102
104
#if FEATURE_ITUPLE
103
- else if ( _state is System. Runtime. CompilerServices. ITuple tuple && tuple. Length == 2 && tuple[ 0 ] is string s )
105
+ else if ( state is System. Runtime. CompilerServices. ITuple tuple && tuple. Length == 2 && tuple[ 0 ] is string s )
104
106
{
105
107
scopeItem = null ; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items.
106
108
107
109
if ( s == SerilogLoggerProvider . OriginalFormatPropertyName && tuple [ 1 ] is string )
108
- scopeItem = new ScalarValue ( _state . ToString ( ) ) ;
110
+ scopeItem = new ScalarValue ( state . ToString ( ) ) ;
109
111
else
110
112
AddProperty ( s , tuple [ 1 ] ) ;
111
113
}
112
114
#else
113
- else if ( _state is ValueTuple< string , object ? > tuple )
115
+ else if ( state is ValueTuple< string , object ? > tuple )
114
116
{
115
117
scopeItem = null ; // Unless it's `FormattedLogValues`, these are treated as property bags rather than scope items.
116
118
117
119
if ( tuple . Item1 == SerilogLoggerProvider . OriginalFormatPropertyName && tuple . Item2 is string )
118
- scopeItem = new ScalarValue ( _state . ToString ( ) ) ;
120
+ scopeItem = new ScalarValue ( state . ToString ( ) ) ;
119
121
else
120
122
AddProperty ( tuple . Item1 , tuple . Item2 ) ;
121
123
}
122
124
#endif
123
125
else
124
126
{
125
- scopeItem = propertyFactory . CreateProperty ( NoName , _state ) . Value ;
127
+ scopeItem = propertyFactory . CreateProperty ( NoName , state ) . Value ;
126
128
}
127
129
}
128
130
}
0 commit comments