Skip to content

Commit

Permalink
Merge pull request #5 from biplovkc/biplovkc-patch-1
Browse files Browse the repository at this point in the history
fix possible null reference on device os, family and browser
  • Loading branch information
biplovkc authored Jun 4, 2023
2 parents 1e58c4e + 563b893 commit d85269f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/HttpContextEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d85269f

Please sign in to comment.