Skip to content

Commit 1a0f83a

Browse files
authored
FUND-1762 Log ApiVersion header (#94)
* Log ApiVersion header * String.Empty used for empty ApiVersion header
1 parent 843f1cc commit 1a0f83a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/OneGround.ZGW.Common.Web/Middleware/EnrichedLoggingMiddleware.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using System;
12
using System.Threading.Tasks;
23
using Microsoft.AspNetCore.Http;
34
using OneGround.ZGW.Common.Extensions;
5+
using OneGround.ZGW.Common.Web.Versioning;
46
using Serilog;
57
using Serilog.Context;
68

@@ -19,6 +21,8 @@ public EnrichedLoggingMiddleware(RequestDelegate next, IDiagnosticContext diagno
1921

2022
public async Task InvokeAsync(HttpContext context)
2123
{
24+
var apiVersion = context.GetRequestedZgwApiVersion()?.ToString() ?? String.Empty;
25+
2226
var rsin = context.GetRsin();
2327
var clientId = context.GetClientId();
2428
var userId = context.GetUserId();
@@ -30,13 +34,15 @@ public async Task InvokeAsync(HttpContext context)
3034
_diagnosticContext.Set("User", user);
3135
_diagnosticContext.Set("RequestHost", context.Request.Host.Value);
3236
_diagnosticContext.Set("RequestScheme", context.Request.Scheme);
37+
_diagnosticContext.Set("ApiVersion", apiVersion);
3338

3439
using var logRsin = LogContext.PushProperty("RSIN", rsin);
3540
using var logClientId = LogContext.PushProperty("ClientId", clientId);
3641
using var logUserId = LogContext.PushProperty("UserId", userId);
3742
using var logUser = LogContext.PushProperty("User", user);
3843
using var logHost = LogContext.PushProperty("RequestHost", context.Request.Host.Value);
3944
using var logSchema = LogContext.PushProperty("RequestScheme", context.Request.Scheme);
45+
using var logApiVersion = LogContext.PushProperty("ApiVersion", apiVersion);
4046

4147
await _next(context);
4248
}

0 commit comments

Comments
 (0)