如何在winforms中创建自动UI事件跟踪? [英] How do I create an automatic UI event trace in winforms?

查看:167
本文介绍了如何在winforms中创建自动UI事件跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要采用现有的winforms应用程序,并放入事件跟踪模式,希望尽可能少的摩擦。

I need to take an existing winforms application and drop into an event tracing mode, with hopefully as little friction as possible.

我想看到用户所采取的每一个动作都是一个简单的堆栈跟踪的东西:

I would like to see every action the user takes as a simple stack trace-looking thing:

MainForm.LaunchThing_Click
ThingWindow.NameInput_Focus
ThingWindow.NameInput_TextChanged
ThingWindow.AddressInput_Focus
ThingWindow.OKButton_Click

等等。


  • 如果这是一个WPF应用程序,我会做一些像过滤所有事件在ETW中的WClientInputMessage类型。

  • 我不能简单地转储堆栈跟踪,因为它不会捕获用户的先前操作。

  • 我可以添加日志记录到每一个事件[从此讨论],但这是一个现存的应用程序远程太多事件。另外,我很懒。可能是一个更好的方法。

  • 我无法附加一个调试器,我想将这些信息自动附加到测试用户的现场的错误报告中,因为没有人可以准确地记录他们点击的事情的顺序。

  • If this was a WPF application, I would do something like filter all events of type WClientInputMessage in ETW.
  • I can't simply dump a stack trace, because that doesn't capture the user's prior actions.
  • I could add logging to every single event [with the recommended practices from this discussion], but this is an extant application with far too many events. Plus, I'm lazy. Gotta be a better way.
  • I can't attach a debugger, I want to get this information automatically attached to bug reports from testing users in the field because [it turns out...] nobody can accurately remember exactly what the sequence of things they clicked on was.

所以我想知道是否有任何人有任何好的技巧,使用子类化或反思可能会锁定UI事件。

So I'm wondering if anyone has any good tricks, using subclassing or reflection perhaps, to latch on to the UI events.

性能并不是一个问题。如果我可以在每个事件中得到一个钩子,那就够了;我可以很容易地将它们过滤到相关的集合中。

Performance is not really a concern. And if I can get a hook into every event, that's good enough; I can filter them down to the relevant set fairly easily.

推荐答案

观察者模式怎么样?创建一个EventLogger类,并使用一系列重载的Log方法(每个事件方法签名一个)进行日志记录。在应用程序启动后实例化它,并将其订阅到每个UI事件。

How about an observer pattern? Create an EventLogger class with a bunch of overloaded Log methods (one for each event method signature) that do the logging. Instantiate it on application start and subscribe it to each of the UI events.

甚至可以通过反思自动进行订阅 - 尽管我认为它更多努力设置,而不是手动为任何合理大小的应用程序。此外,您仍然必须确保您的EventLogger类具有每个可能的事件处理程序方法签名的Log方法。

It should even be possible to do the subscribing automatically with reflection - though I would think it is more effort to set that up than to do it manually for any reasonably sized application. Also you would still have to ensure that your EventLogger class has a Log method for every possible event handler method signature.

这篇关于如何在winforms中创建自动UI事件跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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