Reputation: 6771
I want to display in my application a list of all executed linq to sql queries (with executed time would be nice) on every page for the current request (as a debug information).
Does anybody know how to do that or maybe someone has already build a class to do this?
Thanks!
Upvotes: 3
Views: 1169
Reputation: 59012
The DataContext supports logging through the Log property. Just attach a instance of a TextWriter and you're able to see all statements that are generated. Like this:
var dc = new DataContext();
dc.Log = Console.Out;
This will log all statements to the console window.
I can highly recommend LINQ to SQL log to debug window, file, memory or multiple writers by Damien Guard. He different examples of logging to file, to the console and more.
Another option is to use Linq 2 Sql profiler by Ayende. I have not used it myself but i use NHProf on a daily basis and i'm more than happy with it.
Upvotes: 4