Ejemplo n.º 1
0
        private async Task SendStoredReportAsync(HttpClient client, RaygunFile report)
        {
            try
            {
                RaygunLogger.Verbose("Sending JSON -------------------------------");
                RaygunLogger.Verbose(report.Data);
                RaygunLogger.Verbose("--------------------------------------------");

                // Create the request contnet.
                HttpContent content = new StringContent(report.Data, System.Text.Encoding.UTF8, "application/json");

                // Add API key to headers.
                content.Headers.Add("X-ApiKey", _apiKey);

                // Perform the request.
                var response = await client.PostAsync(RaygunSettings.Settings.ApiEndpoint, content);

                // Check the response.
                var statusCode = (int)response.StatusCode;

                RaygunLogger.LogResponseStatusCode(statusCode);

                // Remove the stored crash report if it was sent successfully.
                if (statusCode == (int)RaygunResponseStatusCode.Accepted)
                {
                    _fileManager.RemoveFile(report.Path); // We can delete the file from disk now.
                }
            }
            catch (Exception e)
            {
                RaygunLogger.Error("Failed to send stored crash report due to error: " + e.Message);
            }
        }
Ejemplo n.º 2
0
        private RaygunFile ReadCrashReportFromDisk(string filePath)
        {
            // Check a file exists with this path.
            if (filePath == null || !File.Exists(filePath))
            {
                return(null);
            }

            var raygunFile = new RaygunFile(filePath);

            // Read in the contents of the file.
            using (var streamReader = new StreamReader(filePath))
            {
                raygunFile.Data = streamReader.ReadToEnd();
            }

            return(raygunFile);
        }