写堆栈跟踪时,一个异常是从另一个线程抛出 [英] Write stack trace when an exception is thrown from another thread

查看:125
本文介绍了写堆栈跟踪时,一个异常是从另一个线程抛出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能写一个未处理的异常(从任何线程抛出)的堆栈跟踪到一个文件?

How can I write the stack trace of an unhandled exception (thrown from any thread) to a file?

我需要这个来帮助调试挂程序。

I need this to help debug a hanging application.

推荐答案

感谢你的一切,但我已经看到了,我在运行程序从Visual Studio一丝认为写的是.NET控制台窗口中的输出时,当从被抛出任何线程未处理的异常不重定向到控制台窗口。

Thanks you all, but I have seen that when I running the program from Visual Studio the output of trace that is written by .NET to the console window when an unhandled exception from any thread is thrown is not redirected to the console window.

这只是重定向当我运行从Visual Studio分离的节目。 所以这个code是挺好看的所有堆栈跟踪从抛出未被处理的异常任何线程

It is just redirected when I run the program separated from Visual Studio. So this code is very good to see all stack trace from any thread that throws an exception which is not handled

Trace.Listeners.Clear();

        TextWriterTraceListener twtl = new TextWriterTraceListener(Path.Combine(Environment.CurrentDirectory, "logfile.txt"));
        twtl.Name = "TextLogger";
        twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime | TraceOptions.Callstack;

        ConsoleTraceListener ctl = new ConsoleTraceListener(false);
        ctl.TraceOutputOptions = TraceOptions.DateTime;

        Trace.Listeners.Add(twtl);
        Trace.Listeners.Add(ctl);
        Trace.AutoFlush = true;

这篇关于写堆栈跟踪时,一个异常是从另一个线程抛出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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