c# logging linq to sql
by brian on Jan.01, 2009, under .NET, c#, linq, mmsql, sql
I’ve often been frustrated by the sql that linq produces. Usually it’s really good, but occasionally it produced monstrosities. The hard part is getting at the sql that’s produced by a function. Hovering over the statement in the idea is a real pain so instead I created the following class that dumps the sql to a file
public class DCLogger : IDisposable
{
private StringWriter writer;
public DCLogger(System.Data.Linq.DataContext dc)
{
writer = new StringWriter();
dc.Log = writer;
}
#region IDisposable Members
public void Dispose()
{
writer.Flush();
System.IO.File.WriteAllText( "c:\\temp\\sql.log", writer.ToString() );
}
#endregion
}
To use it just create it passing it you data context. The results are written to the file when it’s disposed.
using( DCLogger( dc ) )
{
// ... some linq statement that executes
}

December 17th, 2010 on 11:57 am
████████►BUY VIAGRA◀███████…
████████▲▲▲▲▲▲▲▲▲████████…
July 6th, 2011 on 5:44 pm
buy@viagra.online” rel=”nofollow”>……
Need cheap generic VIAGRA?…
July 12th, 2011 on 4:25 pm
buy@generic.abana” rel=”nofollow”>……
Need cheap generic ABANA?…
July 17th, 2011 on 5:29 am
buy@generic.LEVITRA” rel=”nofollow”>……
Need cheap generic LEVITRA?…
July 28th, 2011 on 8:59 pm
Buy@Cheap.Coral.Calcium” rel=”nofollow”>……
Buywithout prescription…
July 29th, 2011 on 1:10 am
Purchase@Coral.Calcium.Online” rel=”nofollow”>……
Buywithout prescription…
July 29th, 2011 on 1:58 am
Purchase@Discount.Coral.Calcium” rel=”nofollow”>..…
Buyit now…
July 29th, 2011 on 2:23 am
Cheap@Coral.Calcium.Online” rel=”nofollow”>..…
Buygeneric meds…
July 29th, 2011 on 4:04 am
Buy@Discount.Abana” rel=”nofollow”>..…
Buyno prescription…
July 29th, 2011 on 6:00 am
Purchase@Abana.Online” rel=”nofollow”>..…
Buydrugs without prescription…
July 29th, 2011 on 7:25 am
Purchase@Cheap.Abana” rel=”nofollow”>……
Buygeneric pills…
July 29th, 2011 on 4:09 pm
Order@Abilify.Without.Prescription” rel=”nofollow”>..…
Buynow it…
July 29th, 2011 on 8:11 pm
Cheap@Generic.Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>..…
Buygeneric pills…
July 30th, 2011 on 1:52 am
Buy@Cheap.Acai” rel=”nofollow”>..…
Buydrugs without prescription…
July 30th, 2011 on 5:36 pm
Get@Acai.Online” rel=”nofollow”>……
Buygeneric drugs…
July 31st, 2011 on 1:02 am
Order@Acai.Without.Prescription” rel=”nofollow”>……
Buynow…
July 31st, 2011 on 10:34 am
Generic@Acai.500mg.Without.Prescription” rel=”nofollow”>..…
Buynow…
July 31st, 2011 on 2:31 pm
Purchase@Coral.Calcium.Online” rel=”nofollow”>..…
Buygeneric drugs…
July 31st, 2011 on 5:52 pm
Order@Cheap.Abana” rel=”nofollow”>.…
Buynow it…
August 1st, 2011 on 11:33 pm
Buy@Cheap.Coral.Calcium” rel=”nofollow”>.…
Buydrugs without prescription…
August 3rd, 2011 on 8:01 am
Buy@Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>……
Buywithout prescription…
August 3rd, 2011 on 11:26 am
Buy@Acai.Online” rel=”nofollow”>.…
Buynow it…
August 3rd, 2011 on 11:57 am
Buy@Acai.Online” rel=”nofollow”>……
Buyno prescription…
August 3rd, 2011 on 12:00 pm
Buy@Acai.Online” rel=”nofollow”>.…
Buyit now…
August 3rd, 2011 on 2:27 pm
Buy@Discount.Acai” rel=”nofollow”>……
Buyit now…
August 3rd, 2011 on 6:27 pm
Order@Cheap.Acai” rel=”nofollow”>……
Buywithout prescription…
August 3rd, 2011 on 6:49 pm
Order@Cheap.Acai” rel=”nofollow”>……
Buygeneric drugs…
August 3rd, 2011 on 7:23 pm
Order@Discount.Acai” rel=”nofollow”>……
Buynow…
August 3rd, 2011 on 9:05 pm
Purchase@Acai.Online” rel=”nofollow”>……
Buynow it…
August 3rd, 2011 on 9:57 pm
Purchase@Cheap.Acai” rel=”nofollow”>……
Buyit now…
August 3rd, 2011 on 11:21 pm
Purchase@Cheap.Acai” rel=”nofollow”>..…
Buywithout prescription…
August 4th, 2011 on 2:08 am
Cheap@Acai.Online” rel=”nofollow”>..…
Buynow it…
August 4th, 2011 on 8:32 am
Buy@Generic.Acai” rel=”nofollow”>..…
Buydrugs without prescription…
August 4th, 2011 on 3:46 pm
Order@Acai.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs…
August 4th, 2011 on 11:21 pm
Buy@Cheap.Energy.Boost” rel=”nofollow”>.…
Buygeneric drugs…
August 5th, 2011 on 1:04 am
Order@Energy.Boost.Online” rel=”nofollow”>.…
Buygeneric drugs…
August 5th, 2011 on 5:40 am
Purchase@Cheap.Energy.Boost” rel=”nofollow”>.…
Buyno prescription…
August 5th, 2011 on 9:52 pm
Get@Accupril.Online” rel=”nofollow”>.…
Buygeneric drugs…
August 6th, 2011 on 5:09 am
Purchase@Accutane.Online” rel=”nofollow”>.…
Buynow it…
August 7th, 2011 on 2:35 am
Buy@Aciphex.Online” rel=”nofollow”>.…
Buygeneric pills…
August 7th, 2011 on 4:26 pm
Cheap@Aciphex.Online” rel=”nofollow”>.…
Buynow it…
August 7th, 2011 on 8:36 pm
Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>.…
Buyno prescription…
August 9th, 2011 on 3:47 am
Order@Acomplia.Online” rel=”nofollow”>.…
Buygeneric meds…
August 9th, 2011 on 5:58 am
Order@Discount.Acomplia” rel=”nofollow”>.…
Buygeneric drugs…
August 9th, 2011 on 11:38 pm
Buy@Actonel.Without.Prescription” rel=”nofollow”>.…
Buygeneric meds…
August 10th, 2011 on 3:24 pm
Cheap@Actonel.Without.Prescription” rel=”nofollow”>.…
Buyno prescription apx…
August 10th, 2011 on 5:34 pm
Purchase@Generic.Actonel.35mg” rel=”nofollow”>..…
Buygeneric drugs krg…
August 10th, 2011 on 11:40 pm
Purchase@Cheap.Actoplus.Met” rel=”nofollow”>.…
Buygeneric drugs zfk…
August 11th, 2011 on 6:09 am
Purchase@Cheap.Actos” rel=”nofollow”>..…
Buynow it vhx…
August 11th, 2011 on 6:44 am
Purchase@Discount.Actos” rel=”nofollow”>……
Buywithout prescription xiu…
August 11th, 2011 on 7:20 am
Cheap@Actos.Online” rel=”nofollow”>..…
Buynow it tly…
August 11th, 2011 on 2:53 pm
Cheap@Generic.Actos” rel=”nofollow”>..…
Buygeneric meds qmo…
August 12th, 2011 on 12:01 am
Purchase@Generic.Actos.15mg.30mg” rel=”nofollow”>..…
Buygeneric pills zdg…
August 12th, 2011 on 1:20 pm
Purchase@Cheap.Adalat” rel=”nofollow”>..…
Buygeneric meds abx…
August 12th, 2011 on 3:58 pm
Buy@Coral.Calcium.Online” rel=”nofollow”>……
Buyit now oil…
August 14th, 2011 on 9:31 am
Get@Acai.Online” rel=”nofollow”>……
Buynow it zdg…
August 14th, 2011 on 11:56 am
Buy@Acai.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs itj…
August 14th, 2011 on 2:54 pm
Order@Acai.Without.Prescription” rel=”nofollow”>.…
Buynow it lmg…
August 15th, 2011 on 5:25 am
Buy@Energy.Boost.Online” rel=”nofollow”>..…
Buynow it cey…
August 15th, 2011 on 12:17 pm
Purchase@Energy.Boost.Online” rel=”nofollow”>..…
Buydrugs without prescription faj…
August 16th, 2011 on 3:28 pm
Get@Accupril.Online” rel=”nofollow”>..…
Buyit now irl…
August 17th, 2011 on 7:57 am
Order@Generic.Accutane” rel=”nofollow”>……
Buygeneric meds svb…
August 17th, 2011 on 11:30 pm
Buy@Cheap.Aciphex” rel=”nofollow”>……
Buywithout prescription ccw…
August 18th, 2011 on 12:45 am
Buy@Discount.Aciphex” rel=”nofollow”>..…
Buyno prescription wkp…
August 18th, 2011 on 5:33 am
Purchase@Aciphex.Online” rel=”nofollow”>……
Buydrugs without prescription vrg…
August 18th, 2011 on 6:43 am
Purchase@Cheap.Aciphex” rel=”nofollow”>.…
Buygeneric drugs axm…
August 18th, 2011 on 9:05 am
Cheap@Aciphex.Online” rel=”nofollow”>..…
Buyno prescription gdt…
August 18th, 2011 on 12:32 pm
Buy@Aciphex.Without.Prescription” rel=”nofollow”>..…
Buyno prescription tao…
August 18th, 2011 on 3:00 pm
Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>……
Buyit now knc…
August 18th, 2011 on 7:27 pm
Purchase@Aciphex.Without.Prescription” rel=”nofollow”>.…
Buydrugs without prescription xab…
August 18th, 2011 on 11:14 pm
Cheap@Aciphex.20mg” rel=”nofollow”>.…
Buyit now ojb…
August 19th, 2011 on 1:41 am
Buy@Generic.Aciphex.20mg” rel=”nofollow”>……
Buydrugs without prescription jlg…
August 19th, 2011 on 8:43 pm
Purchase@Discount.Acomplia” rel=”nofollow”>……
Buydrugs without prescription ttp…
August 21st, 2011 on 1:07 am
Purchase@Discount.Acomplia” rel=”nofollow”>.…
Buydrugs without prescription tdg…
August 21st, 2011 on 1:09 am
Purchase@Discount.Acomplia” rel=”nofollow”>……
Buynow ela…
August 21st, 2011 on 3:55 am
Buy@Actonel.Online” rel=”nofollow”>.…
Buygeneric pills oir…
August 21st, 2011 on 7:52 am
Buy@Discount.Actonel” rel=”nofollow”>..…
Buyno prescription lka…
August 22nd, 2011 on 1:06 am
Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs ouw…
August 22nd, 2011 on 6:26 am
Buy@Cheap.Advair” rel=”nofollow”>.…
Buygeneric drugs hwi…
August 23rd, 2011 on 2:38 am
Purchase@Advair.Online” rel=”nofollow”>..…
Buyno prescription jui…
August 23rd, 2011 on 2:38 pm
Buy@Generic.Advair.Without.Prescription” rel=”nofollow”>..…
Buyno prescription jwi…
August 24th, 2011 on 3:58 am
Buy@Generic.Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>..< …
Buydrugs without prescription hak…
August 24th, 2011 on 10:02 am
Cheap@Generic.Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>…
Buygeneric drugs mby…
August 24th, 2011 on 6:02 pm
Order@Aggrenox.Online” rel=”nofollow”>……
Buyit now sge…
August 26th, 2011 on 12:26 pm
abilify@and.gemfibrozil” rel=”nofollow”>.…
Buyno prescription…
August 26th, 2011 on 7:06 pm
aciphex@cancer.buy” rel=”nofollow”>..…
Buygeneric drugs…
August 27th, 2011 on 12:49 pm
alphagan@refrigerated.buy” rel=”nofollow”>……
Buygeneric drugs…
August 27th, 2011 on 3:07 pm
amantadine@hydrochloride.tablets” rel=”nofollow”>..…
Buygeneric drugs…
August 27th, 2011 on 7:12 pm
arava@adverse.events” rel=”nofollow”>……
Buygeneric meds…
August 28th, 2011 on 3:16 am
can@you.get.acai.berries.in.the.grocery.store” rel=”nofollow”>.…
Buydrugs without prescription…
August 28th, 2011 on 10:04 am
aciphex@muscle.pain” rel=”nofollow”>..…
Buygeneric pills…
August 28th, 2011 on 12:06 pm
actos@side.effects.edema” rel=”nofollow”>..…
Buygeneric drugs…
August 28th, 2011 on 10:52 pm
..…
Buyit now…
August 29th, 2011 on 8:06 am
arjuna@pills.buy” rel=”nofollow”>..…
Buygeneric meds…
August 29th, 2011 on 9:26 am
buy@real.strong.armour” rel=”nofollow”>.…
Buydrugs without prescription…
October 17th, 2011 on 8:33 pm
mike divorce cancer tiffany…
Buy_generic pills…
October 18th, 2011 on 12:49 pm
alberta alcohol and drug abuse commission…
Buy_generic meds…
October 18th, 2011 on 10:49 pm
viagra order uk…
Buy_generic pills…
October 19th, 2011 on 2:09 am
boulder valley asthma and allergy clinic…
Buy_no prescription…
October 19th, 2011 on 5:29 am
weight loss disclaimer law…
Buy_drugs without prescription…
October 20th, 2011 on 1:10 am
recipes for gastric bypass patients…
Buy_now…
October 20th, 2011 on 4:10 pm
what are the trimesters of pregnancy…
Buy_generic drugs…
October 21st, 2011 on 4:01 pm
percent of obese children in usa…
Buy_now it…
October 21st, 2011 on 9:01 pm
weight gain stories feeders…
Buy_drugs without prescription…
October 22nd, 2011 on 5:21 am
accutane birth defects…
Buy_it now…
October 23rd, 2011 on 1:57 am
menstrual patterns in menopause…
Buy_no prescription…
October 24th, 2011 on 2:02 pm
dependent disorder anxiety…
Buy_generic pills…
October 25th, 2011 on 12:02 am
red wine and lipitor…
Buy_no prescription…
October 25th, 2011 on 8:22 am
weight loss doctors in memphis tennessee…
Buy_generic drugs…
October 25th, 2011 on 8:02 pm
is flomax good for prostatitis…
Buy_generic meds…
October 26th, 2011 on 1:02 am
follistim increase estradiol levels…
Buy_generic drugs…
October 26th, 2011 on 6:02 am
herbal flee collars for dogs…
Buy_generic pills…
October 27th, 2011 on 2:02 am
statistics on pregnancy in high school…
Buy_generic meds…
October 27th, 2011 on 3:42 am
cancer of spine…
Buy_without prescription…
October 27th, 2011 on 7:02 am
effexor xr 75…
Buy_generic pills…
October 27th, 2011 on 12:02 pm
herbal essence coupon discount…
Buy_now it…
October 27th, 2011 on 1:42 pm
genital erection…
Buy_now it…
October 27th, 2011 on 3:22 pm
low fat diets history…
Buy_drugs without prescription…
October 28th, 2011 on 7:42 pm
stress from clinical duty…
Buy_without prescription…
October 29th, 2011 on 6:35 am
hives rash from coming off prednisone…
Buy_generic drugs…
October 29th, 2011 on 8:15 am
saline for nebulizer…
Buy_generic pills…
October 29th, 2011 on 7:55 pm
high calorie diet for babies…
Buy_generic drugs…
October 31st, 2011 on 7:39 am
bacterial staphylococcus aureus meningitis symptoms…
Buy_without prescription…
November 1st, 2011 on 12:19 am
how to get teens off drugs…
Buy_drugs without prescription…
November 1st, 2011 on 1:59 am
what is metoprolol succinate used for…
Buy_it now…
November 1st, 2011 on 3:39 am
st joseph aspirin coupon…
Buy_generic pills…
November 1st, 2011 on 10:19 am
zocor and ms…
Buy_it now…
November 1st, 2011 on 4:59 pm
adderall then tylenol pm…
Buy_generic drugs…
November 1st, 2011 on 9:59 pm
abdominal pain lutenizing hormone…
Buy_generic drugs…
November 2nd, 2011 on 7:59 am
ic tramadol hcl 50 mg…
Buy_generic meds…
November 2nd, 2011 on 11:19 am
asthmatic inhaller mask for children…
Buy_it now…
November 3rd, 2011 on 5:39 am
office of generic drug…
Buy_generic drugs…
November 3rd, 2011 on 7:19 am
chronic bronchitis from marijuana…
Buy_now…
November 3rd, 2011 on 6:05 pm
decreased appetite during pregnancy…
Buy_generic drugs…
November 3rd, 2011 on 11:06 pm
hot dog hospital diet substitutions…
Buy_generic drugs…
November 4th, 2011 on 10:46 am
can a woman have colorectal cancer…
Buy_drugs without prescription…
November 4th, 2011 on 5:26 pm
food low in cholesterol…
Buy_now it…
November 5th, 2011 on 6:03 am
hot spots or cancer…
Buy_without prescription…
November 6th, 2011 on 12:23 am
prevacid assistance…
Buy_generic meds…
November 6th, 2011 on 7:03 am
ayurvedic ashwagandha zyban…
Buy_generic pills…
November 7th, 2011 on 4:43 am
allergic reaction to topical miconazole…
Buy_generic meds…
November 8th, 2011 on 2:56 pm
relief of skin itching…
Buy_now it…
November 8th, 2011 on 4:37 pm
clinical diagnosis and medical records…
Buy_generic meds…
November 9th, 2011 on 12:57 am
twin pregnancy obstetrician specialist dallas…
Buy_drugs without prescription…
November 9th, 2011 on 7:37 am
glucophage powered by vbulletin version 2.2.1…
Buy_generic pills…
November 9th, 2011 on 12:37 pm
shampoo for people with dog allergies…
Buy_now…
November 9th, 2011 on 5:36 pm
eye drops canine paralysis…
Buy_now…
November 11th, 2011 on 2:37 pm
medical nebulizer…
Buy_generic meds…
November 15th, 2011 on 1:54 pm
free fast diet tips…
Buy_generic meds…
November 15th, 2011 on 5:14 pm
cause for morning erections…
Buy_generic meds…
November 15th, 2011 on 8:35 pm
drug citalopram side effects…
Buy_generic drugs…
November 16th, 2011 on 6:35 am
inpatient drug rehab sanford fl…
Buy_it now…
November 16th, 2011 on 11:35 am
air purifiers for allergies…
Buy_generic meds…
November 17th, 2011 on 5:55 am
acyclovir stada cream…
Buy_generic drugs…
December 10th, 2011 on 1:04 am
children@prozac.buy” rel=”nofollow”>……
Buywithout prescription…