Fixed AuditInterceptor.cs , add GraphQL error logging, add translation request get
This commit is contained in:
@@ -12,9 +12,24 @@ public class AuditInterceptor : SaveChangesInterceptor
|
||||
InterceptionResult<int> result)
|
||||
{
|
||||
var context = eventData.Context;
|
||||
SetAuditFields(context);
|
||||
|
||||
|
||||
return base.SavingChanges(eventData, result);
|
||||
}
|
||||
|
||||
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result,
|
||||
CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
var context = eventData.Context;
|
||||
SetAuditFields(context);
|
||||
return base.SavingChangesAsync(eventData, result, cancellationToken);
|
||||
}
|
||||
|
||||
private void SetAuditFields(DbContext? context)
|
||||
{
|
||||
if (context == null)
|
||||
return base.SavingChanges(eventData, result);
|
||||
return;
|
||||
|
||||
var entries = context.ChangeTracker.Entries<IAuditable>();
|
||||
|
||||
@@ -32,7 +47,5 @@ public class AuditInterceptor : SaveChangesInterceptor
|
||||
e.Entity.LastUpdatedTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
return base.SavingChanges(eventData, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ public abstract class FictionArchiveDbContext : DbContext
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.AddInterceptors(new AuditInterceptor());
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public void UpdateDatabase()
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using HotChocolate.Execution;
|
||||
using HotChocolate.Execution.Instrumentation;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Services.GraphQL;
|
||||
|
||||
public class ErrorEventListener : ExecutionDiagnosticEventListener
|
||||
{
|
||||
private readonly ILogger<ErrorEventListener> _logger;
|
||||
|
||||
public ErrorEventListener(ILogger<ErrorEventListener> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override void RequestError(IRequestContext context, Exception exception)
|
||||
{
|
||||
_logger.LogError(exception, "An error occurred while processing a GraphQL request.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user