问题使用跟踪监听器重定向调试输出到文件 [英] Problem redirecting debug output to a file using trace listener

查看:222
本文介绍了问题使用跟踪监听器重定向调试输出到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个调试监听器重定向从调试/控制台窗口中的输出到一个文件中(调用堆栈),使用下面的code:

I have created a debug listener to redirect the output from the Debug/Console window to a file(with a call stack), using the following code:

void SomeMethod()
{
    // Create a file for output .txt.
    Stream debugFile = File.Create(fileName);

    // create TextWriterTraceListener named "file"
    TextWriterTraceListener debugWriter = new TextWriterTraceListener(debugFile, "file");

    // add to debug listeners
    Debug.Listeners.Add(debugWriter);
    // set callstack to be shown
    Debug.Listeners["file"].TraceOutputOptions |= TraceOptions.Callstack;
    // set auto-flush
    Debug.AutoFlush = true;
}

但输出将不会重定向到我指定的文件,它总是空的。

but the output won't redirect to the file I specified, it's always empty.

我是从我的主要形式的构造函数调用此。在这里,我从一个问题调用它的地方?

I am calling this from the constructor in my main form. Is the place where I'm calling it from a problem?

我试图在这里实现是有从调试输出窗口放在同一个调用堆栈文件例外,这样我可以找到他们,并予以纠正。

What I am trying to achieve here is to have the exceptions from the Debug output window placed in a file with a call stack, so that I can find them and correct them.

更新:一些研究,我来,添加一个新的的TraceListener 来调试听众的结论后,收集不会重定向从调试/控制台输出。实际上它只是回应的WriteLine 等方法一样默认的监听。 问题仍然存在:如何捕获调试/控制台窗口的输出以及如何让出现有异常的堆栈跟踪

UPDATE: After some research I came to a conclusion that adding a new TraceListener to the Debug Listeners collection does not redirect the output from the Debug/Console. It is actually just responding to Write, WriteLine etc. methods as does the default listener. The problem still remains: How to capture the output of the Debug/Console window and how to get the stack trace of the exceptions that appear there?

任何人有什么想法?

推荐答案

下面是回答了我的问题的一部分一篇文章: HTTP://www.$c$cproject.com/KB/trace/DbMonNET的.aspx

Here's an article that answers a part of my question: http://www.codeproject.com/KB/trace/DbMonNET.aspx

即。如何捕捉调试/控制台窗口的输出。但是,似乎没有办法从这个输出得到堆栈跟踪。展望从这个角度来看,它看起来像一个不错的办法呢。

i.e. how to capture the output of the Debug/Console window. But, it seems that there's no way of getting the stack trace from this output. Looking from this perspective it looks like a bad approach anyway.

进一步研究:貌似这些异常出现,因为它们在未正确连接的其他一些DLL处理,他们处理了我的try / catch块有代替。这可能是在那里我应该寻找我的错误,即在这里有一个dll引用我应该将添加项目引用的地方。

FURTHER RESEARCH: Looks like these exceptions are appearing because they are handled in some other dll that is not linked properly, and they are handled there instead of my try/catch blocks. This is probably the place where I should be looking my error for i.e. where there's a dll reference I should instead add a project reference.

更多的研究:启用打破在Visual Studio的主菜单中的例外:调试 - >例外 - >选中你想要的应用程序,以打破在异常的类型(公共语言运行时)...有没有更好的方式来处理异常。

MORE RESEARCH: Enable breaking at exceptions in Visual Studio main menu: Debug -> Exceptions -> Check the type of exceptions you want the application to break at(Common Language Runtime)...There's no better way to deal with exceptions.

这篇关于问题使用跟踪监听器重定向调试输出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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