5

NHibernate Envers does a good job of creating an Audit Log whenever an entity is Updated/Deleted. Basically it creates an Audit table for each auditable entity and write a snapshot of the data into the Audit table. For e.g. if Customer records are saved in CUSTOMER table then audit log for Customer records will be saved in CUSTOMER_AUD table.

In one of my projects we are using Entity Framework 6.1. I have searched and looked at various alternatives like AuditDBContext and EntityFramework Extensions but none of them provide an out of box solution similar to NHibernate Envers.

I think generating an Audit Log should be a pretty common requirement, so my question is, whether there is any out of box solution for EF 6+ that generates the Audit Log similar to NHibernate Envers?

Deep Shah
  • 420
  • 2
  • 14

2 Answers2

2

I ended up implementing a custom solution using the AuditDBContext.

Basically, I use the AuditDBContext to keep track of what properties have changed and then used that to write information to Audit tables. The audit tables exactly mirror the main tables with two additional columns:

  • REV_TYPE - That indicates the revision type could be Add/Update/Delete
  • REV_ID - Indicates a unique revision id for that row.
Deep Shah
  • 420
  • 2
  • 14
2

Also take a look at https://github.com/bilal-fazlani/tracker-enabled-dbcontext

https://www.nuget.org/packages/TrackerEnabledDbContext

Its a bit different, but worth taking a look at.

Bilal Fazlani
  • 6,727
  • 9
  • 44
  • 90
  • I tried (and liked) this framework, but for larger databases, the AuditLogDetail table becomes huge. Thus, IMHO, it makes sense to split the audit log on a "per-table" basis. – Matthias Wuttke Sep 19 '15 at 07:13