我怎么能写一个未处理的异常(从任何线程抛出)的堆栈跟踪到一个文件?
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;更多推荐
写堆栈跟踪时,一个异常是从另一个线程抛出
发布评论