Skip to content

Commit

Permalink
Review feedback items
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed May 28, 2017
1 parent 6190ca8 commit 60b71b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Serilog/Context/LogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public static IDisposable PushProperty(string name, object value, bool destructu
}

/// <summary>
/// Push an enricher onto context, returning an <see cref="IDisposable"/>
/// Push an enricher onto the context, returning an <see cref="IDisposable"/>
/// 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.
/// </summary>
/// <param name="enricher">Log Properties to push onto the log context</param>
/// <param name="enricher">An enricher to push onto the log context</param>
/// <returns>A token that must be disposed, in order, to pop properties back off the stack.</returns>
/// <exception cref="ArgumentNullException"></exception>
public static IDisposable Push(ILogEventEnricher enricher)
Expand All @@ -107,7 +107,7 @@ public static IDisposable Push(ILogEventEnricher enricher)
/// be popped from the same thread/logical call context.
/// </summary>
/// <seealso cref="PropertyEnricher"/>.
/// <param name="enrichers">Log Properties to push onto the log context</param>
/// <param name="enrichers">Enrichers to push onto the log context</param>
/// <returns>A token that must be disposed, in order, to pop properties back off the stack.</returns>
/// <exception cref="ArgumentNullException"></exception>
public static IDisposable Push(params ILogEventEnricher[] enrichers)
Expand All @@ -129,7 +129,7 @@ public static IDisposable Push(params ILogEventEnricher[] enrichers)
/// Push enrichers onto the log context. This method is obsolete, please
/// use <see cref="Push(Serilog.Core.ILogEventEnricher[])"/> instead.
/// </summary>
/// <param name="properties">Log Properties to push onto the log context</param>
/// <param name="properties">Enrichers to push onto the log context</param>
/// <returns>A token that must be disposed, in order, to pop properties back off the stack.</returns>
/// <exception cref="ArgumentNullException"></exception>
[Obsolete("Please use `LogContext.Push(properties)` instead.")]
Expand Down
30 changes: 30 additions & 0 deletions test/Serilog.Tests/Context/LogContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 60b71b4

Please sign in to comment.