最终用户桌面应用程序中的异常处理流程(捕获、日志、报告、修复)

发布于 2024-08-21 04:01:07 字数 608 浏览 3 评论 0原文

我正在启动一个新项目,一个最终用户桌面应用程序。我担心如果(好吧,当)最终用户遇到未处理的异常时会发生什么。 要求用户帮助我重现错误不是一个可接受的选择。 据我所知,我只剩下一个选择:将错误报告上传到我的服务器。

几年前,当我还是一名 Delphi 开发人员时,一个名为 madExcept 的出色工具可以帮助我完成这一切,但我在 .Net 框架上找不到类似的工具。所以我想我必须自己做。

这是我的想法

  • 使用日志框架并写一些 深思熟虑的日志条目,不太 很多或很少。只需记录到内存中, 更好的性能,我不需要 文件。将日志大小限制为 100KB。

  • 使用 AOP 记录所有方法的参数和返回值,除了那些处于紧密循环中的方法,因为它会使日志混乱并导致性能不佳。这就是我真正没有安全感的一点,在生产中这是一件愚蠢的事情吗?不过,这个好处似乎很有吸引力。我认为我应该能够在更多情况下重现异常,而不仅仅是堆栈跟踪和日志。此外,这还将记录到内存中,并限制为 200KB 之类的内容。

  • 捕获所有未处理的异常,这里我将上传两个日志和堆栈跟踪到我的服务器。

    捕获所有未处理的异常,这里我将

你认为它会起到什么作用?有更好的办法吗?

谢谢

I'm starting a new project, a end-user desktop application. I'm a concerned about what will happened if (ok, when) the end-user gets an unhandled exception.
Asking the user to help me reproduce the bug is not an acceptable option.
As I see it I'm left with one option: to upload an error report to my server.

Years ago when I were a Delphi developer, a great tool called madExcept could help me with all this, but I cannot find a similar tool on the .Net framework. So I guess I have to make my own.

Here is my idea

  • Use a log-framework and write a few
    well thought log entries, not too
    many or few. Just log to memory,
    better performance and I don't need
    the file. Limit the log size to say 100KB.

  • Use AOP to log parameters and return values on all methods, except those in a tight loop as it will clutter the log and cause bad performance. This is the point I'm really insecure about, is this a stupid thing to do in production? The benefit seems very appealing though. I think I should be able to reproduce the exception in a lot more cases, than having just a stack trace and a log. Also this will logged to a memory and limited to something like 200KB.

  • Catch all unhandled exceptions, here I will upload the two logs and stack trace to my server.

What do you think will it work? Is there a better way?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞 2024-08-28 04:01:07

您预计会出现许多未处理的异常吗?

只需在应用程序级别捕获未处理的异常并记录它们。当需要添加附加信息时,请在本地捕获异常:

public void OpenConfigurationFile(string filePath)
{
    try
    {
        File.Open(filePath, ...);
    }
    catch (IOException ex)
    {
        throw new InvalidOperationException(
            String.Format("Can't open configuration file {0}", filePath), ex);
    }
}

这样,您不仅会记录 FileNotFoundException,还会记录它是您试图打开的配置文件这一事实。

Do you expect to have many unhandled exceptions?

Just catch unhandled exceptions at the application level, and log them. Do catch exceptions locally when it's necessary to add additional information:

public void OpenConfigurationFile(string filePath)
{
    try
    {
        File.Open(filePath, ...);
    }
    catch (IOException ex)
    {
        throw new InvalidOperationException(
            String.Format("Can't open configuration file {0}", filePath), ex);
    }
}

That way, you'll not only log the FileNotFoundException, but also the fact that it was a configuration file you were trying to open.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文