Created
July 19, 2012 15:54
-
-
Save yngwie74/3144879 to your computer and use it in GitHub Desktop.
Obtener un log del SQL generado por un DataContext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private TRet WithLogging<T, TRet>(T context, string logmsg, Func<T, TRet> func) where T : DataContext | |
{ | |
TRet result; | |
var log = context.Log; | |
var builder = new StringBuilder(); | |
try | |
{ | |
context.Log = new StringWriter(builder); | |
result = func.Invoke(context); | |
} | |
finally | |
{ | |
Log.InfoFormat("{0}:\n{1}", logmsg, builder); | |
context.Log = log; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quizá parezca demasiada vuelta pero.. que tal esto :) https://gist.github.com/3147119