Marc
Marc

Reputation: 6771

show all linq sql queries per request

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

Answers (1)

alexn
alexn

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

Related Questions