Creating an audit trail

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 02-Mar-2007 00:22:32   

So the business has decided that whenever certain tables are updated they want to save the old and new fields in a table. The table definition would contain the fields AuditLogId, FieldUpdated, OldValue, NewValue, ModifiedByUserId, DateModified.

I cannot decide if I should use subscribe to the AfterSave event of the MyCustomEntity class being saved or if I should override the OnSaveEntityComplete method of the DataAccessAdapterBase.

I am leaning toward using the AfterSave event because that way I can pick and choose what entities I will create an audit log for.

So my questions are 1. is this a sane approach 2. will the event args used in the AfterSave event handler give me access to all of the before and after data to create the audit trail 3. is there some other approach that I am not considering

Please advise.

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 02-Mar-2007 00:44:07   

Ok, so I read all the way through the following thread "Auditing and Temporal Object Best Practices" and it is very long and provides many options.

I am using Adapter scenario, with the 2 class option. I am looking for the simplest approach possible. I am willing to write hand coded logging code into each custom entity that needs an audit log.

Taking these factors into account, would it be advisable to tie the auditing to the entity or the data access adapter?

Thanks again.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Mar-2007 06:40:14   

I am looking for the simplest approach possible.

The simplest approach is Database Triggers.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 02-Mar-2007 12:27:25   

in adapter, it's natural to use the dataaccessadapter as the central point for auditing, as you have access to the transaction and a persistence mechanism. You can also tap into the save mechanism to add auditing entities to the transaction using OnBeforeEntitySave for example.

Frans Bouma | Lead developer LLBLGen Pro