locked
Audit trail using logging block RRS feed

  • Question

  • User411295211 posted

    Hi All,

    I need to implement audit trail in my whole asp.net application. When a record get created, changed or deleted, i need to do an entry in database about username, datetime stamp, old and new record.

    Can you please guide me on how to implement it at asp.net application level.

    Should i use Microsoft Enterprise library logging block for this, as somebody told me that logging block will automatically create database table with all the entries i want.

    Can somebody please verify whether all the columns i mention above will be catered by logging block.

    Cheers

    Thompson

    Wednesday, October 20, 2010 9:47 PM

Answers

  • User214117797 posted

    I need to implement audit trail in my whole asp.net application. When a record get created, changed or deleted, i need to do an entry in database about username, datetime stamp, old and new record.
     

    Just a suggestion, have you considered using database triggers for this?

    Most people dont like using triggers but I think this is a prime example for using a trigger.

    You can create a trigger for onupdate or ondelete and get a hold of the original data and new data and insert into something like an audit table.

    Whilst you can do this in your domain code but either have an abstract auditbase class or something, I personally think database triggers are the way to go.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 20, 2010 10:47 PM
  • User214117797 posted

    Though i understand your suggestion fully, is logging block not the right fit here.

    Also i want to clarify one point here that most of this application funtionalities requires audit trail as this is an healthcare applications and every data entry/change/deletion needs to be saved for audit trail.So do you recommend database triggers on each and every table. Won't it slow the performance of the system.

     

    You can use the Logging Block but that means your business code would be littered with either events or all this wrapping just to manage the change of data. Yes this can be done with base classes, aspect oriented programming etc

    I just like to keep my domain code clean and free of non functional requirements like logging and audit trail. Each person would have their own opinion on this. I personally prefer the trigger option for this scenario as this is independant of the application and if audit requirement changes there is no need to recomplile the code base.

    In terms of speed, there will be overheads whether it be in the application or database as there will be extra calls to the DB and cycles in the CPU, but this in unavoidable. The only benefit is maybe using a queue if you are doing it in your application code but this to me is a minor issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 21, 2010 6:36 PM

All replies

  • User214117797 posted

    I need to implement audit trail in my whole asp.net application. When a record get created, changed or deleted, i need to do an entry in database about username, datetime stamp, old and new record.
     

    Just a suggestion, have you considered using database triggers for this?

    Most people dont like using triggers but I think this is a prime example for using a trigger.

    You can create a trigger for onupdate or ondelete and get a hold of the original data and new data and insert into something like an audit table.

    Whilst you can do this in your domain code but either have an abstract auditbase class or something, I personally think database triggers are the way to go.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 20, 2010 10:47 PM
  • User411295211 posted

    Hi Jimmy,

    Thanks a lot for providing reply in such a short span of time.

    Though i understand your suggestion fully, is logging block not the right fit here.

    Also i want to clarify one point here that most of this application funtionalities requires audit trail as this is an healthcare applications and every data entry/change/deletion needs to be saved for audit trail.So do you recommend database triggers on each and every table. Won't it slow the performance of the system.

    Thanks again

    Cheers

    Thomspon

    Thursday, October 21, 2010 12:00 AM
  • User214117797 posted

    Though i understand your suggestion fully, is logging block not the right fit here.

    Also i want to clarify one point here that most of this application funtionalities requires audit trail as this is an healthcare applications and every data entry/change/deletion needs to be saved for audit trail.So do you recommend database triggers on each and every table. Won't it slow the performance of the system.

     

    You can use the Logging Block but that means your business code would be littered with either events or all this wrapping just to manage the change of data. Yes this can be done with base classes, aspect oriented programming etc

    I just like to keep my domain code clean and free of non functional requirements like logging and audit trail. Each person would have their own opinion on this. I personally prefer the trigger option for this scenario as this is independant of the application and if audit requirement changes there is no need to recomplile the code base.

    In terms of speed, there will be overheads whether it be in the application or database as there will be extra calls to the DB and cycles in the CPU, but this in unavoidable. The only benefit is maybe using a queue if you are doing it in your application code but this to me is a minor issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 21, 2010 6:36 PM