3

I am trying to Send Error reports with hockeyapp without having to let the whole app crash and burn. I dont think the HockeyApp.WPF library has this capability, so I started to mess around with implementing my own CrashHandler.

This quickly got confusing and very hackey. Does anyone have any code examples for this? At my current rate I will end up reproducing half of the HockeyApp Library, so I would appreciate some help.

I am not posting my code because I don't think it will help and its too much.

Edit: now I will post a shortened version of code that doesnt seem to work:

        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;
    }
BillHaggerty
  • 6,157
  • 10
  • 35
  • 68

1 Answers1

5

I was able to make a post after formatting the logs as described in the documentation for the crashes/upload endpoint(http://support.hockeyapp.net/kb/api/api-crashes#-u-post-api-2-apps-app_id-crashes-upload-u-).

Although I ended up hitting "crashes/", which from my understanding is different from crashes/upload(Therefore this is a solution that is hitting an undocumented endpoint).

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");

            }

        }
BillHaggerty
  • 6,157
  • 10
  • 35
  • 68
  • 1
    I am not sure if this wasnt exist in 2015 but today there is Microsoft.HockeyApp.HockeyClient.Current.TrackException(ex, properties); it is in HockeyApp.Core package – Emil Jan 03 '17 at 17:16
  • Probably didn't exist. Not working with Hockey anymore but if you submit an answer and others verify then I will set yours as the accepted one(can I do that, its been a while?). – BillHaggerty Jan 03 '17 at 18:52
  • If I may ask, what Alternative do you use and what kind of app? – Emil Jan 03 '17 at 18:58
  • I am working at a new company now, (old company still uses Hockey for client side mobile apps). For my current project I just do local logging/error reporting via Log4net for console apps and services. I believe that my company uses something called (sematext/logsene) for web server log reporting. – BillHaggerty Jan 03 '17 at 19:30
  • I said "client side mobile apps" but they also had a wpf windows desktop and osx app that used hockey. – BillHaggerty Jan 03 '17 at 19:40