Last active
November 23, 2022 21:13
-
-
Save JuergenGutsch/a711371d3f9577c01eb97db8110bc7c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 class StopwatchMiddleWare | |
{ | |
private readonly RequestDelegate _next; | |
public StopwatchMiddleWare(RequestDelegate next) | |
{ | |
_next = next; | |
} | |
public async Task Invoke(HttpContext context) | |
{ | |
var s = new Stopwatch(); | |
s.Start(); | |
await _next(context); | |
s.Stop(); | |
var result = s.ElapsedMilliseconds; | |
await context.Response.WriteAsync($" Time needed: {result }"); | |
} | |
} | |
public static class StopwatchMiddlewareExtension | |
{ | |
public static IApplicationBuilder UseStopwatch(this IApplicationBuilder app) | |
{ | |
app.UseMiddleware<StopwatchMiddleware>(); | |
return app; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment