Linq to SQL Debug Logging

So today i stumbled upon a Linq to SQL feature i didn’t know of but thought it could be useful. Linq to SQL allows you to attach a logger to the DataContext object. You can quickly log to the Output window with the following code

MyDataContext dataContext = new MyDataContext(connectionString);
dataContext.Log = new DebugTextWriter();

Here is a useful blog i found with some other useful logging tips including custom loggers and logging to multiple loggers.

http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: