Api-PWA/DocuMed.Api/WebFramework/MiddleWares/PerformanceMiddleware.cs

28 lines
783 B
C#
Raw Normal View History

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