问题描述
在VB .NET中,我知道我可以通过查看 ex.StackTrace
的价值得到一个堆栈跟踪处理异常的时候。我怎样才能在堆栈上的功能时,我没有处理异常?我希望实施某种形式的日志系统来记录用户系统崩溃之前采取的措施,协助调试。
In VB .NET, I know I can get a stack trace by looking at the value of ex.StackTrace
when handling an exception. How can I get the functions on the stack when I am not handling an exception? I am looking to implement a logging system of some sort to record the steps the user takes prior to a crash to assist in debugging.
推荐答案
Environment.StackTrace
给你一个字符串,但更详细的信息和选项,使用堆栈跟踪
类。
Environment.StackTrace
gives you a string, but for more detailed information and options, use the StackTrace
class.
要更具体,检查出的构造函数选项:
To be more specific, check out the constructor options:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.stacktrace.aspx
如果您需要的堆栈跟踪的调用者的帧开始(例如,在记录功能:你不想要的一切开始与 MyLogMethod
),你应该试试这个一个,这需要一个 INT
参数,跳帧的数量。
If you need the stack trace starting at the caller's frame (e.g. in a logging function: you don't want everything to start with MyLogMethod
), you should try this one, which takes an int
parameter, the number of frames to skip.
http://msdn.microsoft.com/en-us/library/wybch8k4.aspx
如果你需要没有源堆栈跟踪信息,(例如:如果你不想放弃你的源$ C $ C信息),试试这个:
If you need the stack trace without source information (e.g. if you don't want to give away information about your source code), try this one:
http://msdn.microsoft.com/en-us/library/6zh7csxz.aspx
希望帮助!
这篇关于如何得到正常执行.NET中的堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!