File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
src/Serilog.Extensions.Hosting/Extensions/Hosting Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ namespace Serilog.Extensions.Hosting
10
10
public sealed class DiagnosticContextCollector : IDisposable
11
11
{
12
12
readonly AmbientDiagnosticContextCollector _ambientCollector ;
13
+ readonly object _propertiesLock = new object ( ) ;
13
14
List < LogEventProperty > _properties = new List < LogEventProperty > ( ) ;
14
15
15
16
internal DiagnosticContextCollector ( AmbientDiagnosticContextCollector ambientCollector )
@@ -24,7 +25,11 @@ internal DiagnosticContextCollector(AmbientDiagnosticContextCollector ambientCol
24
25
public void Add ( LogEventProperty property )
25
26
{
26
27
if ( property == null ) throw new ArgumentNullException ( nameof ( property ) ) ;
27
- _properties ? . Add ( property ) ;
28
+
29
+ lock ( _propertiesLock )
30
+ {
31
+ _properties ? . Add ( property ) ;
32
+ }
28
33
}
29
34
30
35
/// <summary>
@@ -36,10 +41,13 @@ public void Add(LogEventProperty property)
36
41
/// <returns>True if properties could be collected.</returns>
37
42
public bool TryComplete ( out List < LogEventProperty > properties )
38
43
{
39
- properties = _properties ;
40
- _properties = null ;
41
- Dispose ( ) ;
42
- return properties != null ;
44
+ lock ( _propertiesLock )
45
+ {
46
+ properties = _properties ;
47
+ _properties = null ;
48
+ Dispose ( ) ;
49
+ return properties != null ;
50
+ }
43
51
}
44
52
45
53
/// <inheritdoc/>
You can’t perform that action at this time.
0 commit comments