【问题标题】:Send handled Exception report using HockeyApp(Windows)使用 HockeyApp(Windows) 发送已处理的异常报告
【发布时间】:2015-03-13 14:58:20
【问题描述】:

我正在尝试使用 hockeyapp 发送错误报告,而不必让整个应用程序崩溃和烧毁。我不认为 HockeyApp.WPF 库有这个能力,所以我开始搞乱实现我自己的CrashHandler

这很快就变得令人困惑并且非常骇人听闻。有没有人有任何代码示例?以我目前的速度,我最终会复制一半的 HockeyApp 库,因此我将不胜感激。

我没有发布我的代码,因为我认为它不会有帮助而且它太多了。

编辑:现在我将发布一个似乎不起作用的缩短版本的代码:

        private static void HandleException(Exception e) {
        try {
            string crashID = Guid.NewGuid().ToString();
            String filename = String.Format("{0}{1}.log", CrashFilePrefix, crashID);

            CrashLogInformation logInfo = new CrashLogInformation() {
                PackageName = Application.Current.GetType().Namespace,
                Version = ((HockeyClient)HockeyClient.Current).VersionInfo,
                OperatingSystem = Environment.OSVersion.Platform.ToString(),
                Windows = Environment.OSVersion.Version.ToString() + Environment.OSVersion.ServicePack,
                Manufacturer = "",
                Model = ""
            };

            ICrashData crash = ((HockeyClient)HockeyClient.Current).CreateCrashData(e);
            using (FileStream stream = File.Create(Path.Combine(GetPathToHockeyCrashes(), filename))) {
                crash.Serialize(stream);
                stream.Flush();
            }
        }
        catch (Exception ex) {
            ((HockeyClient)HockeyClient.Current).HandleInternalUnhandledException(ex);
        }
    }
    private static string GetPathToHockeyCrashes() {
        string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
        if (!path.EndsWith("\\")) { path += "\\"; }
        path += "HockeyCrashes\\";
        if (!Directory.Exists(path)) { Directory.CreateDirectory(path); }
        return path;
    }


    private struct CrashLogInformation {
        /// <summary>
        /// name of app package
        /// </summary>
        public string PackageName;
        /// <summary>
        /// version of app
        /// </summary>
        public string Version;
        /// <summary>
        /// os
        /// </summary>
        public string OperatingSystem;
        /// <summary>
        /// device manufacturer
        /// </summary>
        public string Manufacturer;
        /// <summary>
        /// device model
        /// </summary>
        public string Model;
        /// <summary>
        /// product id of app
        /// </summary>
        public string ProductID;
        /// <summary>
        /// windows phone version
        /// </summary>
        public string WindowsPhone;
        /// <summary>
        /// windows version
        /// </summary>
        public string Windows;
    }

【问题讨论】:

    标签: c# wpf windows exception-handling hockeyapp


    【解决方案1】:

    按照崩溃/上传端点 (http://support.hockeyapp.net/kb/api/api-crashes#-u-post-api-2-apps-app_id-crashes-upload-u-) 文档中的说明格式化日志后,我能够发帖。

    虽然我最终遇到了“崩溃/”,但据我了解,这与崩溃/上传不同(因此,这是一个解决未记录端点的解决方案)。

    private static readonly string HOCKEYUPLOADURL = @"https://rink.hockeyapp.net/api/2/apps/{0}/crashes/";
    
         private static async Task SendDataAsync(String log, String userID, String contact, String description) {
                string rawData = "";
                rawData += "raw=" + Uri.EscapeDataString(log);
                if (userID != null) {
                    rawData += "&userID=" + Uri.EscapeDataString(userID);
                }
                if (contact != null) {
                    rawData += "&contact=" + Uri.EscapeDataString(contact);
                }
                if (description != null) {
                    rawData += "&description=" + Uri.EscapeDataString(description);
                }
                WebRequest request = WebRequest.Create(new Uri(String.Format(HOCKEYUPLOADURL, HOCKEYAPPID)));
    
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                using (Stream stream = await request.GetRequestStreamAsync()) {
                    byte[] byteArray = Encoding.UTF8.GetBytes(rawData);
                    stream.Write(byteArray, 0, rawData.Length);
                    stream.Flush();
                }
    
                try {
                    using (WebResponse response = await request.GetResponseAsync()) { }
                }
                catch (WebException e) {
                    WriteLocalLog(e, "HockeyApp SendDataAsync failed");
    
                }
    
            }
    

    【讨论】:

    • 我不确定这在 2015 年是否不存在,但今天有 Microsoft.HockeyApp.HockeyClient.Current.TrackException(ex, properties);它在 HockeyApp.Core 包中
    • 可能不存在。不再与 Hockey 合作,但如果您提交答案并且其他人验证,那么我会将您的答案设置为接受的答案(我可以这样做吗,已经有一段时间了?)。
    • 如果我可以问,您使用什么替代方案以及什么样的应用程序?
    • 我现在在一家新公司工作,(旧公司仍然使用 Hockey 作为客户端移动应用程序)。对于我当前的项目,我只是通过 Log4net 为控制台应用程序和服务进行本地日志记录/错误报告。我相信我的公司使用称为 (sematext/logsene) 的东西来进行 Web 服务器日志报告。
    • 我说的是“客户端移动应用”,但他们也有一个使用曲棍球的 wpf Windows 桌面和 osx 应用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-03
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 2018-12-12
    相关资源
    最近更新 更多