@@ -11,7 +11,7 @@ public sealed class DiagnosticContextCollector : IDisposable
11
11
{
12
12
readonly IDisposable _chainedDisposable ;
13
13
readonly object _propertiesLock = new object ( ) ;
14
- List < LogEventProperty > _properties = new List < LogEventProperty > ( ) ;
14
+ Dictionary < string , LogEventProperty > _properties = new Dictionary < string , LogEventProperty > ( ) ;
15
15
16
16
/// <summary>
17
17
/// Construct a <see cref="DiagnosticContextCollector"/>.
@@ -34,17 +34,7 @@ public void AddOrUpdate(LogEventProperty property)
34
34
lock ( _propertiesLock )
35
35
{
36
36
if ( _properties == null ) return ;
37
-
38
- for ( var i = 0 ; i < _properties . Count ; ++ i )
39
- {
40
- if ( _properties [ i ] . Name == property . Name )
41
- {
42
- _properties [ i ] = property ;
43
- return ;
44
- }
45
- }
46
-
47
- _properties . Add ( property ) ;
37
+ _properties [ property . Name ] = property ;
48
38
}
49
39
}
50
40
@@ -55,11 +45,11 @@ public void AddOrUpdate(LogEventProperty property)
55
45
/// </summary>
56
46
/// <param name="properties">The collected properties, or null if no collection is active.</param>
57
47
/// <returns>True if properties could be collected.</returns>
58
- public bool TryComplete ( out List < LogEventProperty > properties )
48
+ public bool TryComplete ( out IEnumerable < LogEventProperty > properties )
59
49
{
60
50
lock ( _propertiesLock )
61
51
{
62
- properties = _properties ;
52
+ properties = _properties ? . Values ;
63
53
_properties = null ;
64
54
Dispose ( ) ;
65
55
return properties != null ;
0 commit comments