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
1010 public sealed class DiagnosticContextCollector : IDisposable
1111 {
1212 readonly AmbientDiagnosticContextCollector _ambientCollector ;
13+ readonly object _propertiesLock = new object ( ) ;
1314 List < LogEventProperty > _properties = new List < LogEventProperty > ( ) ;
1415
1516 internal DiagnosticContextCollector ( AmbientDiagnosticContextCollector ambientCollector )
@@ -24,7 +25,11 @@ internal DiagnosticContextCollector(AmbientDiagnosticContextCollector ambientCol
2425 public void Add ( LogEventProperty property )
2526 {
2627 if ( property == null ) throw new ArgumentNullException ( nameof ( property ) ) ;
27- _properties ? . Add ( property ) ;
28+
29+ lock ( _propertiesLock )
30+ {
31+ _properties ? . Add ( property ) ;
32+ }
2833 }
2934
3035 /// <summary>
@@ -36,10 +41,13 @@ public void Add(LogEventProperty property)
3641 /// <returns>True if properties could be collected.</returns>
3742 public bool TryComplete ( out List < LogEventProperty > properties )
3843 {
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+ }
4351 }
4452
4553 /// <inheritdoc/>
You can’t perform that action at this time.
0 commit comments