Skip to content

Commit db1e058

Browse files
FIX: Enrich context before collecting properties
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.
1 parent fd6bf02 commit db1e058

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ bool LogCompletion(HttpContext httpContext, DiagnosticContextCollector collector
7878

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

81-
if (!collector.TryComplete(out var collectedProperties))
82-
collectedProperties = NoProperties;
83-
8481
// Enrich diagnostic context
8582
_enrichDiagnosticContext?.Invoke(_diagnosticContext, httpContext);
8683

84+
if (!collector.TryComplete(out var collectedProperties))
85+
collectedProperties = NoProperties;
86+
8787
// Last-in (correctly) wins...
8888
var properties = collectedProperties.Concat(new[]
8989
{

0 commit comments

Comments
 (0)