I am using Audit.Net for generating audit logs in my entity framework core project where I use Database First Approach. While I am able to get some promising results I have a few question:
- While using AuditTypNameMapper is there a way to ignore entities that do not have a corresponding audit entity (eg. I have Customer entity and AuditCustomer but I do not have AuditCustomeOrder entity for Customer Order entity).
- I am not able to generate a Transaction id for dynamic audit entity.
Here is my code for the following:
`
Audit.Core.Configuration.Setup()
.UseEntityFramework(x => x
.AuditTypeNameMapper(typeName => "Audit" + typeName)
.AuditEntityAction((evt, entry, auditEntity) =>
{
// auditEntity is object
var a = (dynamic)auditEntity;
a.AuditDate = DateTime.UtcNow;
a.UserId = evt.Environment.UserName;
a.AuditAction = entry.Action; // Insert, Update, Delete
a.Changes = JsonConvert.SerializeObject(entry.Changes);
a.TransactionId = evt.GetEntityFrameworkEvent().TransactionId;
}));
` Like in the configuration code in the official docs:
`Audit.Core.Configuration.Setup()
.UseEntityFramework(x => x
.AuditTypeNameMapper(typeName => "Audit_" + typeName)
**.AuditEntityAction<IAudit>((ev, ent, auditEntity)** =>
{
var entityFrameworkEvent = ev.GetEntityFrameworkEvent();
**auditEntity.TransactionId = entityFrameworkEvent.TransactionId;**
}));`
- I am not able to use the IAudit also like in the config code. That is the reason I am going for dynamic
Thanks for helping out!