Last post Feb 18, 2019 02:15 AM by Nan Yu
Feb 15, 2019 06:42 PM|Peter Cong|LINK
I am converting a old MS Access application to MVC web app in Visual Studio 2013, the existing MS Access application is similar as VB Web form windows application has audit log feature which records any field data changes , since the form property of Access
framework is different than MVC web application, therefore, the Access application is easy to implement audit log.
Now, I am looking a better way how to implement the Audit log feature in MVC web application, or if there is any plug in to make it easy implement.
For example, if a web razor view is opened, there is no audit log if it is in read mode, but if it is in Edit mode, then I need to compare before and after the field data changes and record it in a table to show before and after the field data, something
like that. For a new record, it is simple, there is not compare for the old field and new field, just save the record with the user ID and timestamp, so the difficulty is the editing of an existing record.
Thanks for any help,
Feb 15, 2019 07:00 PM|mgebhard|LINK
Asking for a "better way" implies you have an existing way. Can you explain and show the existing way?
IMHO, this is better handled in SQL using an UPDATE trigger to populate an audit table.
Feb 18, 2019 02:15 AM|Nan Yu|LINK
Hi Peter Cong ,
On database side , you can try Track Data Changes (SQL Server) :
On application side , if using EF , you can subscribe to the SavingChanges event. and implement the partial method OnContextCreated to hook up the event to update your audit tables :
Or you can try Entity Framework logging libraries like :
or this one :