Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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