Skip to content

Commit

Permalink
Fix for issue ekmsystems#31
Browse files Browse the repository at this point in the history
added unit test for reusing the same correlationId for multiple log entries for second enricher
  • Loading branch information
lkurzyniec committed Nov 12, 2019
1 parent 7f9d3fe commit ba5808a
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,28 @@ public void When_CurrentHttpContextIsNotNull_ShouldNot_CreateCorrelationIdProper
Assert.NotNull(evt);
Assert.IsFalse(evt.Properties.ContainsKey("CorrelationId"));
}

[Test]
public void When_MultipleLoggingCallsMade_Should_KeepUsingCreatedCorrelationIdProperty()
{
var httpContext = new DefaultHttpContext();

A.CallTo(() => _httpContextAccessor.HttpContext)
.Returns(httpContext);

LogEvent evt = null;
var log = new LoggerConfiguration()
.Enrich.With(_enricher)
.WriteTo.Sink(new DelegateSink.DelegatingSink(e => evt = e))
.CreateLogger();

log.Information(@"Has a CorrelationId property");

var correlationId = evt.Properties["CorrelationId"].LiteralValue();

log.Information(@"Here is another event");

Assert.AreEqual(correlationId, evt.Properties["CorrelationId"].LiteralValue());
}
}
}

0 comments on commit ba5808a

Please # to comment.