1

Lately our customers are experiencing unexpected crashes. We are already logging the errors on their local machines. Is there a mechanism to enable them to "send error log" somehow when the application crashes or when unexpected behavior takes place?

In other word how do I know that the application freezed or hung or crashed so I can send something, and override the normal "not responding" windows message?

4

2 回答 2

2

如果它挂起,我认为您无能为力,但如果它崩溃了,您也许可以使用UnhandledExceptionEventHandler捕获其中的一些崩溃。

您可以通过检查应用程序何时启动来处理挂起,如果它以前正确关闭并将“关闭”消息写入日志,如果没有,您可以询问用户是否要将日志发送到你。

于 2010-04-08T08:44:09.563 回答
1

过去,我很幸运能够使用如下代码将异常记录到 Web 服务(只要允许客户端注销到 Internet)。这是用于记录您尚未捕获的任何内容。如果您在发布模式下编译应用程序但还包含 pdb 文件,您将获得带有行号的堆栈跟踪。

您还应该记录程序集的版本,以了解哪个版本的应用程序给您带来错误。

public void RegisterHandlers()
{
    Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionFunction);
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionFunction);
}

private void UnhandledExceptionFunction(object sender, UnhandledExceptionEventArgs args)
{
    Exception e = (Exception)args.ExceptionObject;
    ExceptionLogger(e.StackTrace);
}

private void ThreadExceptionFunction(object sender, ThreadExceptionEventArgs args)
{
    ExceptionLogger(args.Exception.StackTrace);
}

private void ExceptionLogger(string trace)
{
    // log the message to a webservice
}
于 2010-04-08T09:08:34.993 回答