Thursday, 9 August 2012

System.Diagnostics.StackTrace


StackTrace

The .Net frameworks provides the System.Diagnostics.StackTrace class which allows you to get a stack trace at runtime. It is handy for diagnostic purposes. The StackTrace class has following features:

  • It represents the actual stack running.
  • It only shows managed frames and does not show any native frames.
  • The stack trace class can get method names and even IL offsets without symbols

Example
void PrintStackTrace()
{
StackTrace st = new StackTrace(true); // true means get line numbers.
foreach(StackFrame f in st.GetFrames())
{
Console.Write(f);
}

No comments:

Post a Comment