Skip to content

Instantly share code, notes, and snippets.

@stevetalkscode
Last active February 6, 2021 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevetalkscode/ca0703e5b58e26ba6fb18997b27902b8 to your computer and use it in GitHub Desktop.
Save stevetalkscode/ca0703e5b58e26ba6fb18997b27902b8 to your computer and use it in GitHub Desktop.
public class LogUserAgentConventionalMiddleware
{
private readonly RequestDelegate _next;
public LogUserAgentConventionalMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context, ILogger<LogUserAgentConventionalMiddleware> logger)
{
var userAgent = context.Request.Headers.GetCommaSeparatedValues("User-Agent").LastOrDefault();
if (userAgent is not null) logger?.LogTrace($"User Agent : {userAgent}");
await _next(context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment