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.
24 lines
768 B
24 lines
768 B
using System.Data.Common; |
|
using Microsoft.EntityFrameworkCore.Diagnostics; |
|
|
|
namespace ErsatzTV; |
|
|
|
public class SlowQueryInterceptor(int threshold) : DbCommandInterceptor |
|
{ |
|
public override ValueTask<DbDataReader> ReaderExecutedAsync( |
|
DbCommand command, |
|
CommandExecutedEventData eventData, |
|
DbDataReader result, |
|
CancellationToken cancellationToken = default) |
|
{ |
|
if (eventData.Duration.TotalMilliseconds > threshold) |
|
{ |
|
Serilog.Log.Logger.Debug( |
|
"[SLOW QUERY] ({Milliseconds}ms): {Command}", |
|
eventData.Duration.TotalMilliseconds, |
|
command.CommandText); |
|
} |
|
|
|
return base.ReaderExecutedAsync(command, eventData, result, cancellationToken); |
|
} |
|
}
|
|
|