![]() AuditActionType = Create/ Delete/ Update.In the " CreateAuditTrail" method, we send in the following parameters: Using CompareObjects, here is the core code that generates the audit information and inserts it into the database. This package is extremely useful and provides everything we need, its open source and saved me time #JobDone. This technique is based on log tables that are populated by triggers or mechanisms specific to the application that updates the database. It compares objects recursively so can handle quite complex object structures. The most economical option for maintaining an audit trail is to specifically design your database for audit logging. Having tried a few, and my own version, I decided to utilise an existing nuget package Compare net objects. I looked at writing my own reflection code to examine the before/after object state, and found numerous good starting points on slack. Since we are in C#, we can use reflection to examine the data object we have in the database, and compare it to the one we are about to post, and view the differences between the two. The concept is simple - before we post a change to the database, we have a "before" and "after" knowledge of the state of the data. Once we have the scaffolding implemented, we can implement the auditing. This outputs highlighting the record in a red colour: When we call the controller and subsequent model to load the data, we send back a list of records where the " deleted" flag is true or false. You will recall the " Deleted" field for the SampleData table. There are also three action buttons to show " Live records" (i.e.: non-deleted), all records, and to create a new record. The index view is built using MVC Razor syntax on a table, that is styled with boostrap. SampleData rec = (s => s.ID = ID) įor the UI example, I have tweaked the MVC default bootstrap giving a very basic EDIT and Index view: Public bool UpdateRecord(SampleDataModel Rec) Public void CreateRecord(SampleDataModel Rec)ĪuditTestEntities ent = new AuditTestEntities() Įnt.SaveChanges() // save first so we get back the dbRec.ID for audit tracking There are also supporting ViewModels: ViewModel I setup very basic controllers and data model methods to serve the index data up, and allow the crud process. To test the system as designed, I created a simple MVC application that uses Entity Framework. The ValueBefore/ After is optional - depending on the complexity of the system, it may be useful to have a before/after snapshot to enable you to rebuild data on a granular level. Insight generates audit entries for any user activities that affect the storage network or its management, including the following: Logging in. ![]() " ValueBefore/ ValueAfter" stores an XML/JSON snapshot of the DataModel data before/after the change event." Changes" is an XML/JSON representation of the delta/diff between the previous data-state and the change." DataModel" is the name of the Data-Model/View-Model that the change occurred in that we are logging." DateTimeStamp" gives us a point in time when the event occurred." AuditActionTypeENUM" tells us what type of audit record this is (create, edit, delete)." KeyFieldID" stores a link between the Person- SampleData.ID field.In our audit trail table, we use the fields as follows:
0 Comments
Leave a Reply. |