Logging Linq to SQL operations

1 בפברואר 2010

Linq to SQL provide build in logger that logs all select, insert, update and delete operations, it executes. Very helpful tool when something goes wrong. You can find it under DataContext .Log property that takes TextWriter . Most of the samples you probably would find about the logger are setting the Console.Out to it, like this: DataContext dataContext = newMyDataContext(); dataContext.Log = Console.Out; The more common scenario would be to write it to a text file. Changing this code to open a StreamWriter is not so hand: string logFilePath = @"c:\log.txt"; FileStream fileStream = new FileStream(logFilePath, FileMode.OpenOrCreate, FileAccess.Write); TextWriter textWriter =...
תגיות: ,
60 תגובות