Optimized allocation search. Added sql command log interception
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Moonlight.App.Database.Entities;
|
||||
using Moonlight.App.Database.Entities.LogsEntries;
|
||||
using Moonlight.App.Database.Entities.Notification;
|
||||
using Moonlight.App.Database.Interceptors;
|
||||
using Moonlight.App.Models.Misc;
|
||||
using Moonlight.App.Services;
|
||||
|
||||
@@ -65,6 +66,9 @@ public class DataContext : DbContext
|
||||
builder.EnableRetryOnFailure(5);
|
||||
}
|
||||
);
|
||||
|
||||
if(ConfigService.SqlDebugMode)
|
||||
optionsBuilder.AddInterceptors(new SqlLoggingInterceptor());
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Moonlight/App/Database/Interceptors/SqlLoggingInterceptor.cs
Normal file
40
Moonlight/App/Database/Interceptors/SqlLoggingInterceptor.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Data.Common;
|
||||
using Logging.Net;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
|
||||
namespace Moonlight.App.Database.Interceptors;
|
||||
|
||||
public class SqlLoggingInterceptor : DbCommandInterceptor
|
||||
{
|
||||
public override InterceptionResult<DbDataReader> ReaderExecuting(
|
||||
DbCommand command,
|
||||
CommandEventData eventData,
|
||||
InterceptionResult<DbDataReader> result)
|
||||
{
|
||||
LogSql(command.CommandText);
|
||||
return base.ReaderExecuting(command, eventData, result);
|
||||
}
|
||||
|
||||
public override InterceptionResult<object> ScalarExecuting(
|
||||
DbCommand command,
|
||||
CommandEventData eventData,
|
||||
InterceptionResult<object> result)
|
||||
{
|
||||
LogSql(command.CommandText);
|
||||
return base.ScalarExecuting(command, eventData, result);
|
||||
}
|
||||
|
||||
public override InterceptionResult<int> NonQueryExecuting(
|
||||
DbCommand command,
|
||||
CommandEventData eventData,
|
||||
InterceptionResult<int> result)
|
||||
{
|
||||
LogSql(command.CommandText);
|
||||
return base.NonQueryExecuting(command, eventData, result);
|
||||
}
|
||||
|
||||
private void LogSql(string sql)
|
||||
{
|
||||
Logger.Info($"[SQL DEBUG] {sql.Replace("\n", "")}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user