Skip to content

Commit

Permalink
FIX: Enrich context before collecting properties
Browse files Browse the repository at this point in the history
LogCompletion event was not including properties added via
`EnrichDiagnosticContext` delegate on options because
the properties had been collected before invoking the enricher.

Swapping the order of the statements fixes this.
  • Loading branch information
alastair-gatpark committed Nov 7, 2019
1 parent fd6bf02 commit db1e058
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ bool LogCompletion(HttpContext httpContext, DiagnosticContextCollector collector

if (!logger.IsEnabled(level)) return false;

if (!collector.TryComplete(out var collectedProperties))
collectedProperties = NoProperties;

// Enrich diagnostic context
_enrichDiagnosticContext?.Invoke(_diagnosticContext, httpContext);

if (!collector.TryComplete(out var collectedProperties))
collectedProperties = NoProperties;

// Last-in (correctly) wins...
var properties = collectedProperties.Concat(new[]
{
Expand Down

0 comments on commit db1e058

Please sign in to comment.