Environment.StackTrace Environment.StackTrace Environment.StackTrace Environment.StackTrace Property

定義

取得目前的堆疊追蹤資訊。Gets current stack trace information.

public:
 static property System::String ^ StackTrace { System::String ^ get(); };
public static string StackTrace { get; }
member this.StackTrace : string
Public Shared ReadOnly Property StackTrace As String

屬性值

含有堆疊追蹤資訊的字串。A string containing stack trace information. 這個值可以是 EmptyThis value can be Empty.

範例

下列範例示範StackTrace屬性。The following example demonstrates the StackTrace property.

// Sample for the Environment::StackTrace property
using namespace System;
int main()
{
   Console::WriteLine();
   Console::WriteLine( "StackTrace: ' {0}'", Environment::StackTrace );
}

/*
This example produces the following results:

StackTrace: '   at System::Environment::GetStackTrace(Exception e)
at System::Environment::GetStackTrace(Exception e)
at System::Environment::get_StackTrace()
at Sample::Main()'
*/
// Sample for the Environment.StackTrace property
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);
    }
}
/*
This example produces the following results:

StackTrace: '   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.get_StackTrace()
   at Sample.Main()'
*/
' Sample for the Environment.StackTrace property
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'StackTrace: '   at System.Environment.GetStackTrace(Exception e)
'   at System.Environment.GetStackTrace(Exception e)
'   at System.Environment.get_StackTrace()
'   at Sample.Main()'
'

備註

StackTrace屬性清單的相反時間順序的方法呼叫,也就是第一次,所述的最新的方法呼叫和一行的堆疊追蹤資訊會列在堆疊上每個方法呼叫。The StackTrace property lists method calls in reverse chronological order, that is, the most recent method call is described first, and one line of stack trace information is listed for each method call on the stack. 不過,StackTrace屬性可能不會報告如預期般運作,因為發生在最佳化期間的程式碼轉換的多個方法呼叫。However, the StackTrace property might not report as many method calls as expected due to code transformations that occur during optimization.

注意

針對由類別的堆疊追蹤資訊的階層式檢視,使用StackTrace類別。For a hierarchical view of the stack trace information by class, use the StackTrace class.

StackTrace屬性格式化每個方法呼叫的堆疊追蹤資訊,如下所示:The StackTrace property formats the stack trace information for each method call as follows:

「 在FullClassNameMethodName(MethodParams) 中FileName: 列LineNumber""at FullClassName.MethodName(MethodParams) in FileName :line LineNumber "

前面三個空格,加上"at"常值,如果無法使用的偵錯符號,則會忽略整個開頭為"in"的子字串。The literal "at" is preceded by three spaces, and the entire substring starting with "in" is omitted if debug symbols are not available. 預留位置FullClassNameMethodNameMethodParamsFileName,和LineNumber、 以實際的值,取代及定義,如下所示:The placeholders, FullClassName, MethodName, MethodParams, FileName, and LineNumber, are replaced by actual values, and are defined as follows:

FullClassNameFullClassName
類別,包括命名空間的完整名稱。The full name of the class, including the namespace.

MethodName
方法的名稱。The name of the method.

MethodParams
參數類型/名稱組的清單。The list of parameter type/name pairs. 每一組以逗號分隔 (",")。Each pair is separated by a comma (","). 如果,則會忽略這項資訊MethodName不接受任何參數。This information is omitted if MethodName takes no parameters.

FileName
來源名稱檔MethodName方法宣告。The name of the source file where the MethodName method is declared. 如果無法使用的偵錯符號,則會忽略這項資訊。This information is omitted if debug symbols are not available.

LineNumber
在 行號FileName包含從原始程式碼MethodName呼叫堆疊上的指示。The number of the line in FileName that contains the source code from MethodName for the instruction that is on the call stack. 如果無法使用的偵錯符號,則會忽略這項資訊。This information is omitted if debug symbols are not available.

Environment.NewLine字串結束的堆疊追蹤的每一行。The Environment.NewLine string terminates each line of the stack trace.

安全性

EnvironmentPermission
取得的完整存取權限所保護的資源。for full access to the resource protected by the permission. 相關聯的列舉型別: UnrestrictedAssociated enumeration: Unrestricted

適用於