我的标准免责声明:我是该产品的开发人员。
使用我工作的公司编写的产品(运行时智能)(PreEmptive 解决方案),您不仅可以注入错误报告,还可以通过最少的编码来跟踪用户何时使用您的应用程序以及他们正在使用哪些功能。
使用 Dotfuscator 执行代码注入(或 IL 编织),我们将新代码插入到您的应用程序二进制文件中,将使用数据发送回我们设施托管的服务器(或可选地发送到任何其他任意 URL)。如果您将数据发送给我们,我们会为您提供许多强大的分析工具和使用情况报告。
此功能的基本版本将包含在 Visual Studio 2010 中,并且可以访问免费的数据报告门户(但没有 SLA、数据保留保证或数据隐私)。
将任意数据与使用信息一起发回的能力仅限于商业产品,但您可以联系 PreEmptive Solutions 以获得功能齐全、免费时间有限的评估版本。
您可以使用下面的示例代码完成错误报告:
public partial class app : Application {
// field to temporarily store exception data
private Exception exp;
void AppStartup(object sender, StartupEventArgs args) {
// add a handler to catch any unhandled exceptions
this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(ErrorHandler);
Window1 mainWindow = new Window1();
mainWindow.ShowDialog();
}
// this will prompt the user if they want to report the exception
void ErrorHandler(object sender, DispatcherUnhandledExceptionEventArgs e) {
this.exp = e.Exception;
if (MessageBox.Show("A " + exp.Message + " exception happened, should I report it?", "Error Occurrend", MessageBoxButton.YesNo) == MessageBoxResult.Yes) {
ErrorHappened();
e.Handled = true;
}
}
// this method is called by the above ErrorHandler method and when run through Dotfuscator additional code will be injected into this method that will send a usage data message back to the server and the data in the dictionary (which will be exception data) returned by the ErrorData method will be included into the message and be stored and reported on the server
[Feature("Exception", EventType = FeatureEventTypes.Tick, ExtendedKeySourceElement = SourceElements.Method, ExtendedKeySourceName = "ErrorData")]
private void ErrorHappened() {
// This is here as a placeholder for the exception feature attribute which will exit the application when executed
AppShutdown(true);
}
// this method takes the exception data from the exp field and returns it as a dictionary of name/value pairs
public Dictionary<string, string> ErrorData() {
var retval = new Dictionary<string,string>();
if (null != exp) {
retval.Add("Error Message",exp.Message);
retval.Add("Stack Trace",exp.StackTrace);
}
return retval;
}
}