in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

LINQ to SQL Logging

The other day I was reading Charlie Calvert's excellent post on LINQ and Deferred Execution and stumbled upon a logging feature inside LINQ to SQL.  By setting the Log property to a TextWriter (in this case Console.Out), LINQ to SQL will log the query and what parameters it sent to the database server.  Assign it before you execute your query like this.

MyDataContext.Log = Console.Out;

Obviously you don't have to log to the console, you can log to any text writer.  This provides a great way to log what queries are going to the database and helps eliminate the mystery of what queries have been executing in your application.  Obviously, you can view these queries in the debugger, but once your application is in production, this is a good solution.

Published Feb 21 2008, 09:24 AM by CoreyRoth
Filed under: ,

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems