From 563b893dfb02a853d2c220cb3f671bc62ab62d89 Mon Sep 17 00:00:00 2001 From: BiplovKC Date: Sun, 4 Jun 2023 17:09:29 +0200 Subject: [PATCH] Update HttpContextEnricher.cs --- src/HttpContextEnricher.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/HttpContextEnricher.cs b/src/HttpContextEnricher.cs index 15948d1..d0ddbff 100644 --- a/src/HttpContextEnricher.cs +++ b/src/HttpContextEnricher.cs @@ -36,9 +36,14 @@ public static void HttpRequestEnricher(IDiagnosticContext diagnosticContext, Htt diagnosticContext.Set("IpAddress", httpContextInfo.IpAddress); diagnosticContext.Set("Protocol", httpContextInfo.Protocol); diagnosticContext.Set("Scheme", httpContextInfo.Scheme); - diagnosticContext.Set("Device", clientInfo.Device.Family); - diagnosticContext.Set("OperatingSystem", clientInfo.OS.Family); - diagnosticContext.Set("Browser", clientInfo.UA.Family); + if (!string.IsNullOrWhiteSpace(clientInfo?.Device?.Family)) + diagnosticContext.Set("Device", clientInfo.Device.Family); + + if (!string.IsNullOrWhiteSpace(clientInfo?.OS?.Family)) + diagnosticContext.Set("OperatingSystem", clientInfo.OS.Family); + + if (!string.IsNullOrWhiteSpace(clientInfo?.UA?.Family)) + diagnosticContext.Set("Browser", clientInfo.UA.Family); } private static string GetUserInfo(IPrincipal user) => user.Identity is { IsAuthenticated: true } ? user.Identity.Name : Environment.UserName;