【发布时间】:2013-10-06 22:21:58
【问题描述】:
我希望能够将 c# 中的堆栈跟踪打印到 txt 文件,如下所述。 请注意以下内容:
- 我知道 Ex.Message 不会得到堆栈跟踪。我想使用 FileHandler 将 StackTrace 消息写入文本文件。
-
FileHandler 类的内部代码并不重要。我想知道如何获取此处捕获的异常的堆栈跟踪。
try { //some code } // I just inherit from exception class (the message member, nothing big here) catch (CustomException ex) { //I want to write the stacktrace here instead of the ex.Message FileHandler.Write("DeveloperErrors.txt", "Stack Trace" + ex.Message, System.IO.FileMode.Append); }
【问题讨论】:
-
-1 表示极度缺乏研究工作。
-
考虑使用实际的日志系统。
-
这就是为什么我发布了以下来源中的答案。但是这些并不表示在程序中断时获取异常的当前堆栈跟踪。 Ex.StackTrace 似乎最接近
-
你不想要当前的堆栈跟踪;你想要错误发生的堆栈跟踪。
标签: c# stack-trace file-handling