如何得到正常执行.NET中的堆栈跟踪? [英] How to get a stack trace in .NET in normal execution?

查看:354
本文介绍了如何得到正常执行.NET中的堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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:

<一个href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.stacktrace.aspx">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.

<一个href="http://msdn.microsoft.com/en-us/library/wybch8k4.aspx">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:

<一个href="http://msdn.microsoft.com/en-us/library/6zh7csxz.aspx">http://msdn.microsoft.com/en-us/library/6zh7csxz.aspx

希望帮助!

这篇关于如何得到正常执行.NET中的堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆