Building in an Audit Trail

Apr 30, 2012 at 5:30 PM

I have a requirement to track all changes made by users.

I thought that perhaps I could hook into the ModifyXXX methods, even put the code into the .tt template. I just want to confirm whether they fire before the actual property value is changed, as I would need to get a hold of both the old value as well as the new value.

Or is there another better place to build in an audit trail?

Coordinator
Apr 30, 2012 at 7:32 PM

When a ModifyXxx method exists, it is called instead of directly updating the property  -  that's why you need to set the property within the Modify method (as shown in the code snippets).

N.B.  I would encourage you to try these things out first  e.g. by just writing a Modify method and putting breakpoints in to see when it is called, and the values as they stand.  That's the best way to figure out what's going on. 

If you are recording an audit trail, you might want to cache all the changed values (captured in Modify methods) and then then record them all in one go using the Updating or Updated life-cycle method. (See manual for the difference between them).

Apr 30, 2012 at 8:58 PM

"When a ModifyXxx method exists, it is called instead of directly updating the property  -  that's why you need to set the property within the Modify method (as shown in the code snippets)."

Thanx. Sorry, I missed that in the manual and the code samples. Makes sense.

"If you are recording an audit trail, you might want to cache all the changed values (captured in Modify methods) and then then record them all in one go using the Updating or Updated life-cycle method. (See manual for the difference between them)."

At least I do know the difference between Updating and Updated life cycle events. :) So you agree that this approach is the best, or at least a good approach? There is not something superior you can recommend?

I also had thoughts of using the reflector at runtime to detect changes somehow rather than generating code.

Anyway. Thanx much.

Coordinator
Apr 30, 2012 at 9:04 PM

It has long been my desire to move auditing down into the framework using reflection, so that you could just annotate an action or properties to indicate whether (and potentially how) you want it to be audited.  But until we get some more time/resources freed up  -  or we have a need to do it as part of a commercial contract  -  it isn't going to happen for a while.

Apr 30, 2012 at 11:16 PM

Yeah, that is the kind of thing I had in mind.

Mm. I hope a commercial contract comes up soon that has that as a requirement. :)