Closed MohMehrnia closed 4 years ago
I'm not familiar with Audit.NET, but looking at their docs, I think the only thing you'd need to do is make a data provider/storage sink, override the InsertEvent and ReplaceEvent methods, and use the log methods:
public override object InsertEvent(AuditEvent auditEvent)
{
logger.LogInfo("Audit event recorded: {event}", auditEvent);
return auditEvent;
}
OK thanks, But If solved with this structure
using Audit.Core;
using Audit.EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TurbineJobMVC.Models.Entites;
using TurbineJobMVC.Models.EntitiesConfigure;
namespace TurbineJobMVC.Models
{
public class PCStockDBContext : AuditDbContext
{
private readonly ILogger<PCStockDBContext> _logger;
public DbSet<WorkOrderTBL> WorkOrderTBL { get; set; }
public DbSet<WorkOrder> WorkOrder { get; set; }
public DbSet<TahvilForms> TahvilForms { get; set; }
public PCStockDBContext(ILogger<PCStockDBContext> logger) :base()
{
Audit.Core.Configuration.Setup().UseNullProvider();
_logger = logger;
}
public PCStockDBContext(DbContextOptions options, ILogger<PCStockDBContext> logger) :base(options)
{
Audit.Core.Configuration.Setup().UseNullProvider();
_logger = logger;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.EnableSensitiveDataLogging(false);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ApplyConfiguration<WorkOrderTBL>(new WorkOrderTBLConfigure());
modelBuilder.ApplyConfiguration<WorkOrder>(new BaseViewConfigure<WorkOrder>());
modelBuilder.ApplyConfiguration<TahvilForms>(new TahvilFormsConfigure());
}
public override void OnScopeCreated(AuditScope auditScope)
{
Database.BeginTransaction();
}
public override void OnScopeSaving(AuditScope auditScope)
{
try
{
_logger.LogInformation("Audit event recorded: {event}", auditScope.Event);
}
catch (Exception)
{
Database.CurrentTransaction.Rollback();
throw;
}
Database.CurrentTransaction.Commit();
}
}
}
how do merge with audit.net