1

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:

  1. 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).
  2. 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;**
    }));` 
  1. 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!

007
  • 21
  • 3

1 Answers1

1

You can return true/false on your AuditEntityAction to indicate if you want to include/exclude the entity from the audits.

https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.EntityFramework/README.md#ef-provider-configuration

I don't understand your second and third question.

thepirat000
  • 12,362
  • 4
  • 46
  • 72