如何截取C#中的调试信息(Debugview样式)? [英] How to intercept debugging information ( Debugview style ) in C#?

查看:593
本文介绍了如何截取C#中的调试信息(Debugview样式)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了测试目的,我计划将一个应用程序放在一起,该应用程序将侦听来自应用程序的特定事件,并与之进行交互。

For testing purposes I'm planning to put together a little app that will listen for a particular event coming from an application and interact with it at that point.

鉴于我们在测试过程中改变应用程序代码是不成问题的,从我的角度来看,理想是听来自应用程序的调试跟踪,有点像调试视图,并作出回应。

Given that we're at a point in the testing process where changing the application code is out of the question, the ideal from my point of view would be to listen to the debugging trace from the application, a little like debugview does, and respond to that.

任何人都可以提供有关最佳方式的指导?

Can anyone offer guidance on how best to go about this?

推荐答案

我发现这样做的方式使用了 Mdbg工具,让我从运行时访问核心调试信息。我使用的代码的基本形状如下所示:

The way I found to do it used the Mdbg tools from Microsoft to give me access from the runtime to the core debugging information. The basic shape of the code I'm using looks like this:

 MDbgEngine mg;
 MDbgProcess mgProcess;
 try
 {
       mg = new MDbgEngine();
       mgProcess = mg.Attach(debugProcess.Id);
 }
 catch (Exception ed)
 {
       Console.WriteLine("Exception attaching to process " + debugProcess.Id );
       throw (ed);
 }
 mgProcess.CorProcess.EnableLogMessages(true);
 mgProcess.CorProcess.OnLogMessage += new LogMessageEventHandler(HandleLogMessage);
 mg.Options.StopOnLogMessage = true;
 mgProcess.Go().WaitOne();
 bool running = true;
 Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
  while (running)
   {
       try
       {
           running =mgProcess.IsAlive;
           mgProcess.Go().WaitOne();
        }
        catch
         {
            running = false;
         }
     }

它似乎工作得很好,我需要的任何速度,也许它将为发现自己在同一条船上的任何人提供一个有用的模板。

It seems to work well enough for what I need at any rate, perhaps it will provide a useful template to anyone else who finds themselves in the same boat.

这篇关于如何截取C#中的调试信息(Debugview样式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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