Api/Netina.Api/WebFramework/MiddleWares/PerformanceMiddleware.cs

26 lines
755 B
C#
Raw Permalink Normal View History

2024-04-16 20:01:34 +03:30
namespace Netina.Api.WebFramework.MiddleWares;
2023-12-16 20:25:12 +03:30
public static class PerformanceMiddlewareExtensions
{
public static IApplicationBuilder UsePerformanceMiddlewar(this IApplicationBuilder applicationBuilder)
{
return applicationBuilder.UseMiddleware<PerformanceMiddleware>();
}
}
2024-08-09 21:55:16 +03:30
public class PerformanceMiddleware(
RequestDelegate next,
ILogger<ExceptionHandlerMiddleware> logger)
2023-12-16 20:25:12 +03:30
{
2024-08-09 21:55:16 +03:30
private readonly Stopwatch _timer = new();
2023-12-16 20:25:12 +03:30
public async System.Threading.Tasks.Task Invoke(HttpContext context)
{
_timer.Start();
2024-08-09 21:55:16 +03:30
await next(context);
2023-12-16 20:25:12 +03:30
_timer.Stop();
var elapsedMilliseconds = _timer.ElapsedMilliseconds;
2024-08-09 21:55:16 +03:30
logger.LogWarning($"REQUEST TIMER : {elapsedMilliseconds}");
2023-12-16 20:25:12 +03:30
}
}