diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index accfe9da0..b4ebd2e37 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -80,12 +80,12 @@ public static IDisposable PushProperty(string name, object value, bool destructu } /// - /// Push an enricher onto context, returning an + /// Push an enricher onto the context, returning an /// that must later be used to remove the property, along with any others that /// may have been pushed on top of it and not yet popped. The property must /// be popped from the same thread/logical call context. /// - /// Log Properties to push onto the log context + /// An enricher to push onto the log context /// A token that must be disposed, in order, to pop properties back off the stack. /// public static IDisposable Push(ILogEventEnricher enricher) @@ -107,7 +107,7 @@ public static IDisposable Push(ILogEventEnricher enricher) /// be popped from the same thread/logical call context. /// /// . - /// Log Properties to push onto the log context + /// Enrichers to push onto the log context /// A token that must be disposed, in order, to pop properties back off the stack. /// public static IDisposable Push(params ILogEventEnricher[] enrichers) @@ -129,7 +129,7 @@ public static IDisposable Push(params ILogEventEnricher[] enrichers) /// Push enrichers onto the log context. This method is obsolete, please /// use instead. /// - /// Log Properties to push onto the log context + /// Enrichers to push onto the log context /// A token that must be disposed, in order, to pop properties back off the stack. /// [Obsolete("Please use `LogContext.Push(properties)` instead.")] diff --git a/test/Serilog.Tests/Context/LogContextTests.cs b/test/Serilog.Tests/Context/LogContextTests.cs index a6bf641ac..4809f2bff 100644 --- a/test/Serilog.Tests/Context/LogContextTests.cs +++ b/test/Serilog.Tests/Context/LogContextTests.cs @@ -70,6 +70,36 @@ public void LogContextCanBeCloned() } } + [Fact] + public void ClonedLogContextCanSharedAcrossThreads() + { + LogEvent lastEvent = null; + + var log = new LoggerConfiguration() + .Enrich.FromLogContext() + .WriteTo.Sink(new DelegatingSink(e => lastEvent = e)) + .CreateLogger(); + + ILogEventEnricher clonedContext; + using (LogContext.PushProperty("A", 1)) + { + clonedContext = LogContext.Clone(); + } + + var t = new Thread(() => + { + using (LogContext.Push(clonedContext)) + { + log.Write(Some.InformationEvent()); + } + }); + + t.Start(); + t.Join(); + + Assert.Equal(1, lastEvent.Properties["A"].LiteralValue()); + } + [Fact] public void MoreNestedPropertiesOverrideLessNestedOnes() {