简体   繁体   English

如何将跟踪侦听器附加到正在运行的进程?

[英]How do I attach a trace listener to a running process?

I'm not sure if this is possible in the manner I am envisioning or not so I'm hoping someone can help me wrap my head around this. 我不确定这是否可能以我想象的方式进行,所以我希望有人可以帮助我解决这个问题。

I'm wanting to inject a TraceListener into a running process - kind of. 我想将一个TraceListener注入到一个正在运行的进程中 - 有点像。 I don't actually care how I attach to the process, but the end goal is to listen to the trace output of the running process and dump it out to a console window. 我实际上并不关心如何附加到进程,但最终目标是侦听正在运行的进程的跟踪输出并将其转储到控制台窗口。

I can attach to the process okay, and I can write a TraceListener okay... where I'm coming unstuck is the bit in the middle. 我可以附加到这个过程好了,我可以编写一个TraceListener好吧...我在哪里解开是有点中间。 Anyone got any clue if this can be done? 如果能做到这一点,任何人都有任何线索? If so, can you give me a push in the right direction because I can't see the forest for the trees here. 如果是这样,你能不能给我一个正确的方向,因为我在这里看不到森林的树木。

Maybe I'm trying to approach this in the wrong way? 也许我试图以错误的方式解决这个问题?

I don't think this is practical. 我认为这不实用。 It would be easy to create a listener at runtime, but that is something the App has to do, it involves adding something to a list. 在运行时创建一个监听器会很容易,但这是App必须要做的事情,它涉及到向列表添加内容。

You may want to make sure the Default listener isn't removed and use an OutputDebug tool to listen in. 您可能希望确保不删除默认侦听器并使用OutputDebug工具进行侦听。

Would DbgView from Sysinternals be enough for your needs? 来自Sysinternals的DbgView能满足您的需求吗? It will show you the trace messages of all running processes without having you to configure a trace listener prior to starting the process. 它将向您显示所有正在运行的进程的跟踪消息,而无需在启动进程之前配置跟踪侦听器。

When I want to view debug output, I use a combination of log4net and DebugView . 当我想查看调试输出时,我使用log4netDebugView的组合。 I can make log4net monitor a configuration file to allow me to change the log4net logging level at runtime, or I can use filters in DebugView. 我可以让log4net监视一个配置文件,允许我在运行时更改log4net日志记录级别,或者我可以在DebugView中使用过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM