在.Net核心Web应用程序中,我使用Audit.EntityFramework 16.1.1
和.net core 3.1
来记录更改,用于两个目的:
- 记录特定表的更改以用于历史/安全和
- 将所有更改记录到一个表中(计划的作业(job)定期删除该表),以便在需要时进行一些基本的取证.
在Startup.cs
中使用的代码如下:
var currentUser = app.ApplicationServices.GetRequiredService<ICurrentUser>();
Audit.Core.Configuration.Setup()
.UseEntityFramework(ef => ef
.AuditTypeMapper(t => typeof(AuditLog))
.AuditEntityAction<AuditLog>((ev, entry, entity) =>
{
entity.Id = Guid.NewGuid();
entity.AuditData = entry.ToJson();
entity.EntityType = entry.EntityType.Name;
entity.AuditDate = DateTime.Now;
entity.AuditUsername = currentUser.GetUsername();
entity.AuditUserId = currentUser.GetUserId();
entity.EntityId = entry.PrimaryKey.Count > 1 ?
string.Join("|", entry.PrimaryKey.Select(pk => pk.Value)) :
entry.PrimaryKey.First().Value.ToString();
entity.Action = entry.Action;
})
.IgnoreMatchedProperties(true));
Audit.Core.Configuration.Setup()
.UseEntityFramework(ef => ef
.AuditTypeExplicitMapper(m => m
.Map<Table1, Table1History>((table, tableHistory) =>
{
FillTableHistoryData(table, tableHistory);
})
.Map<Table2, Table2History>((otherTable, otherTableHistory) =>
{
FillOtherTableHistoryData(otherTable, otherTableHistory);
})
在将应用程序升级到.net core 6
和Audit.EntityFramework
到19.1.0
(或任何更新版本)后,这就停止了工作.返回到16.1.1.
会抛出MethodNotFoundException
(对于GetTableName
方法).
所以,我想避免一些严重的重构,同时让它像以前一样工作.在这方面有经验的人能给我一个正确的方向吗?