-
-
Save stevetalkscode/caf86c44fafa4d9e29747394726f1167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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