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.

  1. Leave a comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: