3

I have a requirement where I have to put audit log feature in an existing Asp.net Web Forms application in C# using SQL Server 2008. There are various pages in this application which use from formviews, listviews, gridviews for inserting, updating and deleting data. The requirement is to capture each 3 of these events with data which was modified/deleted, the user details and timestamp.

I want ideas/suggestions as to how I can easily implement this (the code in the application side) and with the use of just one AuditLog table (database side). This is my initial design of the table:

- AuditId uniqueidentifier
- TableName varchar(100)
- RecordId varchar(100) (some tables have int as primary and some have guid)
- Action char(1) (I - insert, U - update, D - delete)
- RecordData varchar(MAX) (dump all data for that record, not sure about this field, need help??)
- ActionDate datetime 
- ActionedBy varchar(20) (user)

Thanks in advance...

Bat_Programmer
  • 6,717
  • 10
  • 56
  • 67

1 Answers1

1

What technology are you using for data access? With EF, you can handle the SavingChanges event:

http://www.codeproject.com/Articles/34491/Implementing-Audit-Trail-using-Entity-Framework-Pa

With NHibernate, implementing IInterceptor:

http://nhforge.org/wikis/howtonh/creating-an-audit-log-using-nhibernate-events.aspx

Oscar
  • 13,594
  • 8
  • 47
  • 75
  • im using datasets and tableadapters – Bat_Programmer May 30 '13 at 08:38
  • That's a bad design and will make you write code in every Inser-Update-Delete method of your DAL. – Oscar May 30 '13 at 08:40
  • well thats how it is and i need ideas on tackling this? – Bat_Programmer May 30 '13 at 08:48
  • As I see this, you have two choices: redesign the application if future changes like this are going to take place, or write code in every Inser-Update-Delete method of your DAL manually. Is the price to pay when you use RAD tools for evolving applications: maintainability becomes a head ache. – Oscar May 30 '13 at 08:53