Environment.StackTrace 属性

定义

获取当前的堆栈跟踪信息。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
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace)
   End Sub
End Class
'
'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()'
'

注解

@No__t-0 属性以反向时间顺序列出方法调用,也就是说,将首先描述最近的方法调用,并为堆栈上的每个方法调用列出一条堆栈跟踪信息。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.

@No__t-0 属性为每个方法调用设置堆栈跟踪信息的格式,如下所示:The StackTrace property formats the stack trace information for each method call as follows:

"FullClassNameMethodNameMethodParams)在 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 和 @no__t)将替换为实际值,并按如下所示定义: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
@No__t-0 中的行号,其中包含调用堆栈上指令的 @no__t 中的源代码。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.

@No__t-0 字符串终止堆栈跟踪的每一行。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

适用于