How to Setup Audit.Net?

1.5k views Asked by At

I have a project that I inherited and I am trying to add audit.net to it. It is a .NET Core application that is split up too a few different projects.

I want to incorporate audit.net with EF Core and hopefully have everything in 1 audit table.

I been looking into the "Audit.EntityFramework" extension but I not sure how to get it to work with my project and how to get if possible everything into 1 audit table.

I added the "AuditDBContext" to my DbContext via the inheritance method

public class MyDbContext : AuditDbContext, IApplicationDbContext
{
}

I then added this on top of myDbContext class

[AuditDbContext(Mode = AuditOptionMode.OptIn, IncludeEntityObjects = false, AuditEventType = "{database}_{context}" )]
public class MyDbContext : AuditDbContext, IApplicationDbContext
{
}

I then tried to use the AuditInclude on top of one of my classes and then ran the project but no audit table is created.

[AuditInclude]
public class TestEntity
{
}

I don't know if this is because the Entity is not in the same project as the MyDBContext which required me to put the nuget package in both the projects or if I missed some setup set.

0

There are 0 answers