Base solution for your next web application
Open Closed

Detailed audit log - Best way to implement with ABP #3198


User avatar
0
exlnt created

My application has a business requirement to capture a detailed audit log of any changes made to "person" entity. My app needs to capture all of the values listed below. (I have already created a custom entity/table with the above columns).

TableName RecordId ColumnName BeforeValue AfterValue

What would be the best method to implement this audit trail using the ASPNETZERO/ABP template solution?


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    This is in our long term plan but we didn't decide how to do it yet. You can try to use domain events for this, see <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/EventBus-Domain-Events">https://aspnetboilerplate.com/Pages/Doc ... ain-Events</a>.

    Whenever a change made for Person entity, you can insert records to your new audit table.

    Thanks.

  • User Avatar
    0
    exlnt created

    I did some further research. It looks like EF has most of the work done for us on the save changes event.

    <a class="postlink" href="https://msdn.microsoft.com/en-us/data/jj556205">https://msdn.microsoft.com/en-us/data/jj556205</a>

    <a class="postlink" href="https://stackoverflow.com/questions/11635451/implementing-oncontextcreated-for-auditing-by-assigning-savechanges-an-eventhand">https://stackoverflow.com/questions/116 ... -eventhand</a>

    <a class="postlink" href="https://www.codeproject.com/Articles/34491/Implementing-Audit-Trail-using-Entity-Framework-Pa">https://www.codeproject.com/Articles/34 ... amework-Pa</a>

    Since the actual "save changes" in the ABP template solution is done by the ABP classes. Can you guide me on how I can use the above examples with ABP template?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Actually you can override SaveChanges in your DbContext and place any code there.