Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.Use(async (context, next) =>
{
var userAgent = context.Request.Headers.GetCommaSeparatedValues("User-Agent").LastOrDefault();
if (userAgent is not null)
{
// Note that as ILogger<T> requres a type, we have to use Startup
// here which doesn't really seem right!
var logger = app.ApplicationServices.GetRequiredService<ILogger<Startup>>();
logger?.LogTrace($"User Agent : {userAgent}");
}
await next();
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment