1. 程式人生 > >c# FrameworkAPI之StackTrace、StackFrame

c# FrameworkAPI之StackTrace、StackFrame

名稱空間:

StackTrace 堆疊 跟蹤

StackFrame 堆疊 幀

StackTrace st = new StackTrace(true);
string stackIndent = "";
for(int i =0; i< st.FrameCount; i++ )
{
    // Note that at this level, there are four
    // stack frames, one for each method invocation.
    StackFrame sf = st.GetFrame(i);
    Console.WriteLine();
    Console.WriteLine(stackIndent + " Method: {0}",sf.GetMethod() );
    Console.WriteLine(stackIndent + " File: {0}", sf.GetFileName());
    Console.WriteLine(stackIndent + " Line Number:{0}",sf.GetFileLineNumber());stackIndent += "  ";
}