Logging SQL String in DAAB Using PIAB

Topics: Data Access Application Block, Logging Application Block, Policy Injection Application Block
Apr 7, 2009 at 7:06 PM
I find that I write a bunch of these type of statements to log SQL executed in my DAOs:

Logger.Write(Sql, Sql", 1, 1, TraceEventType.Verbose)

Where the Sql variable is the Sql to be executed by DAAB.

I am figuring that there must be a way to log the sql executed by DAAB using PIAB and thus removing all that code. Has anyone done this and is willing to share some code/config snippets?

Thanks,
Chanan

 

 

Apr 8, 2009 at 2:24 AM
Why not just pass your sql statements as parameter to some method and configure a policy that will also log the parameters?


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 8, 2009 at 11:40 AM
Two Reasons why thats not ideal:

1. I may have multipile types of operations that I would need to do such as ExecuteReader, ExecuteDataSet, etc. So it cannot be a function that acctually exectues the statement.

2. That leaves us with creating a dummy function that does nothing other then allow me to intercpet it for logging purposes such as: LogMe(Sql). While this will work, it is a bit ugly - I am replacing the one line of Logger.write(sql) with LogMe(sql) - Hardly what I would think AOP should give me... It would be more useful to intercept DAAB and log it there.

Chanan.
Apr 8, 2009 at 12:20 PM
Slightly off topic, but I am surprised that all the application blocks don't have a way to turn on and off logging for the various operations happening inside of them. In the case of DAAB it could log the sql, the time to execute, the number of results, etc. In the case of other blocks, there are other "interesting" things that could be logged. Like in Hibernate where you can turn on logging of the Sql statements.

Maybe something that could be added to V5.0?