mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
using ErsatzTV.Core; |
|
using Microsoft.Extensions.Logging; |
|
|
|
namespace ErsatzTV.Infrastructure; |
|
|
|
using System.Diagnostics; |
|
|
|
public class SlowApiHandler(ILogger<SlowApiHandler> logger) : DelegatingHandler |
|
{ |
|
protected override async Task<HttpResponseMessage> SendAsync( |
|
HttpRequestMessage request, |
|
CancellationToken cancellationToken) |
|
{ |
|
if (SystemEnvironment.SlowApiMs > 0) |
|
{ |
|
var stopwatch = Stopwatch.StartNew(); |
|
|
|
var response = await base.SendAsync(request, cancellationToken); |
|
|
|
stopwatch.Stop(); |
|
|
|
if (stopwatch.ElapsedMilliseconds > SystemEnvironment.SlowApiMs.Value) |
|
{ |
|
string uri = request.RequestUri?.ToString() ?? "Unknown URI"; |
|
string method = request.Method.Method; |
|
|
|
logger.LogDebug( |
|
"[SLOW API] {Method} {Uri} took {Milliseconds}ms", |
|
method, |
|
uri, |
|
stopwatch.ElapsedMilliseconds); |
|
} |
|
|
|
return response; |
|
} |
|
|
|
return await base.SendAsync(request, cancellationToken); |
|
} |
|
}
|
|
|