namespace NetinaShop.Api.WebFramework.MiddleWares; public static class PerformanceMiddlewareExtensions { public static IApplicationBuilder UsePerformanceMiddlewar(this IApplicationBuilder applicationBuilder) { return applicationBuilder.UseMiddleware(); } } public class PerformanceMiddleware { private readonly ILogger _logger; private readonly RequestDelegate _next; private readonly Stopwatch _timer; public PerformanceMiddleware( RequestDelegate next, ILogger logger) { _next = next; _logger = logger; _timer = new Stopwatch(); } public async System.Threading.Tasks.Task Invoke(HttpContext context) { _timer.Start(); await _next(context); _timer.Stop(); var elapsedMilliseconds = _timer.ElapsedMilliseconds; _logger.LogWarning($"REQUEST TIMER : {elapsedMilliseconds}"); } }