如何将跟踪侦听器附加到正在运行的进程?
我不确定这是否可以按照我设想的方式实现,所以我希望有人可以帮助我解决这个问题。
我想将 TraceListener 注入到正在运行的进程中 - 有点。我实际上并不关心如何附加到进程,但最终目标是监听正在运行的进程的跟踪输出并将其转储到控制台窗口。
我可以附加到进程,我可以编写一个 TraceListener,好吧……我遇到的问题是中间的部分。有人知道这是否可以做到吗?如果是这样,你能帮我推向正确的方向吗,因为我在这里只见树木不见森林。
也许我试图以错误的方式处理这个问题?
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. 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. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这不切实际。在运行时创建监听器很容易,但这是应用程序必须做的事情,它涉及向列表添加一些内容。
您可能需要确保默认侦听器未删除并使用 OutputDebug 工具 来听。
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.
You may want to make sure the Default listener isn't removed and use an OutputDebug tool to listen in.
Sysinternals 的 DbgView 是否足够您的需求?它将向您显示所有正在运行的进程的跟踪消息,而无需您在启动进程之前配置跟踪侦听器。
Would DbgView from Sysinternals be enough for your needs? It will show you the trace messages of all running processes without having you to configure a trace listener prior to starting the process.
当我想查看调试输出时,我使用 log4net 和 调试视图。我可以让 log4net 监视配置文件,以允许我在运行时更改 log4net 日志记录级别,或者我可以在 DebugView 中使用过滤器。
When I want to view debug output, I use a combination of log4net and DebugView. 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.