From db1e0580f68e08580970db3d70b3c63294b3a3a1 Mon Sep 17 00:00:00 2001 From: Alastair Green Date: Thu, 7 Nov 2019 12:06:36 +0000 Subject: [PATCH] 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. --- .../AspNetCore/RequestLoggingMiddleware.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs b/src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs index 7618641..e6c17f1 100644 --- a/src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs +++ b/src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs @@ -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[] {