Skip to content

Commit

Permalink
One additional test for LogContext when the PermitCrossAppDomainCalls…
Browse files Browse the repository at this point in the history
… option is enabled.
  • Loading branch information
nblumhardt committed Jul 6, 2015
1 parent 9be1488 commit e8ed475
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/Serilog.Tests/Context/LogContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ public async Task ContextPropertiesCrossAsyncCalls()
}
}

[Test]
public async Task ContextPropertiesPersistWhenCrossAppDomainCallsAreEnabled()
{
LogEvent lastEvent = null;

var log = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Sink(new DelegatingSink(e => lastEvent = e))
.CreateLogger();

LogContext.PermitCrossAppDomainCalls = true;

using (LogContext.PushProperty("A", 1))
{
var pre = Thread.CurrentThread.ManagedThreadId;

await Task.Delay(1000);

var post = Thread.CurrentThread.ManagedThreadId;

log.Write(Some.InformationEvent());
Assert.AreEqual(1, lastEvent.Properties["A"].LiteralValue());

// No problem if this happens occasionally.
if (pre == post)
Assert.Inconclusive("The test was marshalled back to the same thread after awaiting");
}
}

// Must not actually try to pass context across domains,
// since user property types may not be serializable.
// Fails if the Serilog assemblies cannot be loaded in the
Expand Down

0 comments on commit e8ed475

Please sign in to comment.