Thanks jfs, but the link in your option # 1 is no longer good. There is no corresponding article in it. Chris B's link to an MSDN article helped me.
Here is my solution, as my application is not console:
TextWriter tw = new StringWriter(); db.Log = tw; IQueryable<Customer> custQuery = from cust in db.Customers where cust.City == "London" select cust; string output = tw.ToString();
Sagar
source share