Solved

.NET Audit Log Design

Posted on 2014-11-27
9
195 Views
Last Modified: 2014-12-14
I am looking for advice on a high level design approach to build an audit trail for a financial application.  Need to track every change made to every financial record.  Our development team has spent much time and effort using SQL triggers to detect record-level changes.  This turned out to be a major disaster as it caused significant performance problems.  How are audit mechanisms effectively implemented in large .NET applications?  Thanks in advance!
0
Comment
Question by:dev775
9 Comments
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40468545
Which SQL Server version are you working with?
What you want to audit/track? i.e., do you want to record the columns changed and keep track to the previous value and the  new value or you just want to record who changed the data (no matter which) and when?
0
 

Author Comment

by:dev775
ID: 40468559
Our software currently supports SQL 2008 or 2012.  What do we want to keep track of... a) any change to a data field; b) when a record was accessed (even if only to view); c) date/time of change; d) who made the change; & d) from what workstation the change was made.  We need to have a sequential record of changes and yes, we need a history of the actual values that were changed.  For example if a customer phone number is changed we would want to record previous value and new value.
0
 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40468571
Ok, then I will suggest you to get into SQL Server Audit starting by reading this good article in MSDN.
You can create an audit and set it to write in a log file and what you want to audit may be performed by this command example:
CREATE DATABASE AUDIT SPECIFICATION PCI_Txn_Database_Spec
FOR SERVER AUDIT PCI_Audit
  ADD (DATABASE_OBJECT_PERMISSION_CHANGE_GROUP),
  ADD (SELECT ON dbo.Customer BY dbo),
  ADD (INSERT ON dbo.Customer BY dbo),
  ADD (UPDATE ON dbo.Customer BY dbo),
  ADD (DELETE ON dbo.Customer BY dbo),
  ADD (EXECUTE ON dbo.usp_SubmitPO BY public)

Open in new window

0
 
LVL 11

Expert Comment

by:melmers
ID: 40468581
Hello,

i would think when you use the Event Sourcing pattern for your application it could,
be archiveid what you want. as Reference you could read http://msdn.microsoft.com/en-us/library/dn589792.aspx or http://martinfowler.com/eaaDev/EventSourcing.html

But it comes to the cost that your application has an higher performance request and you need
to design this explicit and can't use ORM Mapper out of the box.

When you have an application with this pattern you can audit or rollback to any state of change
if you only use this pattern for database access. If you use other strategies like ORM or direct SQL for
some task then your data can be corrupted and not rollback complete because the event store has not
record all changes.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:dev775
ID: 40469318
Thanks for the helpful comments.  Regarding the SQL Server Audit, what is the likely cost on performance from the standpoint of the client application user?  Will it be possible to store the audit data in another SQL DB?
0
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40469648
Auditing is a common example of a CROSS-CUTTING CONCERN. Because of the SRP principle, i suggest that you didn't implement it at the dataaccess layer/database level and instead at the aplication domain.

Using a DECORATOR pattern you can easily add such behaviour to your project
http://en.wikipedia.org/wiki/Decorator_pattern

Best regards

PD: I forget to add that this design makes your system very TESTABLE
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40470138
In the article I sent in my previous post you can see a table comparing the performance impact with the use of trace. Auditing will always has impact no matter the solution you chose but my recommendation is to use the native SQL Server Audit since has better performance than traces and so will impact less.
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 40470647
The only way to do what you want outside of 3rd party products is SQL Server Audit.

Be aware, though, that this is not an easy thing to learn and implement.  You'll need plenty of time for defining, testing and verifying the audit setup, and verifying that all accesses are being logged as expected.

Also, once Audit is in place on for an instance, it's a prerequisite for that instance: if there's an Audit error during SQL start up, the instance can't start up at all.
0
 

Author Closing Comment

by:dev775
ID: 40499291
Thank you for your help!  --Rob
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now