Skip to content

Commit

Permalink
Merge pull request #1 from biplovkc/feature/user-agent
Browse files Browse the repository at this point in the history
feature: enrich logs with user-agent
  • Loading branch information
biplovkc authored Feb 12, 2023
2 parents a0ae804 + 84e8ea1 commit cfd9953
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/HttpContextEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static void HttpRequestEnricher(IDiagnosticContext diagnosticContext, Htt
Route = httpContext.Features.Get<IEndpointFeature>()?.Endpoint?.Metadata
.GetMetadata<RouteNameMetadata>()?.RouteName
};

var userAgent = httpContext.Request.Headers?.FirstOrDefault(s => "user-agent".Equals(s.Key, StringComparison.OrdinalIgnoreCase)).Value;
httpContextInfo.UserAgent = userAgent is not null ? userAgent.ToString() : "";

diagnosticContext.Set("HttpContext", httpContextInfo, true);
}

Expand Down
2 changes: 2 additions & 0 deletions src/HttpContextInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
internal class HttpContextInfo
{
public string? IpAddress { get; set; }
public string UserAgent { get; set; }
public string Host { get; set; }
public string Protocol { get; set; }
public string Scheme { get; set; }
public string User { get; set; }
public string? Route { get; set; }

}

0 comments on commit cfd9953

Please sign in to comment.