Skip to content

Instantly share code, notes, and snippets.

@stevetalkscode
Last active February 6, 2021 11:10
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/caf86c44fafa4d9e29747394726f1167 to your computer and use it in GitHub Desktop.
Save stevetalkscode/caf86c44fafa4d9e29747394726f1167 to your computer and use it in GitHub Desktop.
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