Thanks greatly to amitgajjar for this solution.
This solution use the in-built
DataContext.Log
property. Since in my situation I am running this as a website and so multiple
DataContext
s may exist, I used a static method to create all my
DataContext
s and assign to their
Log
property the static
StringWriter
I wanted to use for the log. The code looked as follows:
public static class DatabaseHandler
{
public static System.IO.StringWriter LogStream = new System.IO.StringWriter();
internal static DatabaseDataContext CreateDatabaseContext()
{
DatabaseDataContext TheContext = new DatabaseDataContext();
TheContext.Log = LogStream;
return TheContext;
}
}
And then I had an aspx page that simply set it's ouput to type "text" and did
DatabaseHandler.LogStream.GetStringBuilder().ToString()
to get the log.
This is a very efficient and neat solution, thanks so much again to amitgajjar.
Hope this helps anyone else in need,
Ed