views:

345

answers:

2

I am aware of many table auditing methods. Some are trigger based and require triggers on each table to be audited. SOme have limitation based on column datatype. How can I use a logging framework like NLog or Log4Net. I want my log(in a table) to answer question " Who updated this column of this table from val0 to val1 at this time?"

I have not decided on a OR mapper yet. Inclining towards NHibernate or EF.

Thanks in advance !

+2  A: 

If you use a pattern like DAO (I use it successfully in Java with Hibernate) you can add an entry for every change in the database. If you use Spring.NET you can use AOP for adding interceptors to the methods of the DAOs accessing the database.

Anyway, you might want to add a special appender for the DAOs package because it would be very verbose.

victor hugo
inclined towards Postsharp..but AOP sounds a good option
Perpetualcoder
+1  A: 

Victors answer is top notch but I wanted to add that this may be hard depending on how your column->object mappings work.

If your mapping your table columns to object properties and fields with different names then I think you'll looking at trying to parse sql information to determine which column was updated. For example if your changed the value of "Product.Price" and that actually maps to a column named "final_price" your logging won't exactly match up to whats happening in the database.

Also this could be wrong but if your working with disconnected entities through an ORM package I'm not sure if change tracking information will be available. I vaguely remember a problem I read about where one of the ORMs you listed were updating every column so it appeared a user changed all the columns in the table when they really updated a single column.

jfar