1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| StackTrace stackTrace = new StackTrace(); // get call stack
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
try
{
dtBase = EnterpriseLibraryContainer.Current.GetInstance<Database>();
}
catch (Exception e)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Public\Exception.txt"))
{
file.WriteLine(e.Message);
}
}
finally
{
// Example #3: Write only some strings in an array to a file.
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Public\WriteLines.txt"))
{
// write call stack method names
foreach (StackFrame stackFrame in stackFrames)
{
file.WriteLine(stackFrame.GetMethod().Name);
}
}
} |