private void SendStoredMessages() { lock (_sendLock) { if (!ValidateApiKey()) { System.Diagnostics.Debug.WriteLine("ApiKey has not been provided, skipping sending stored Raygun messages"); return; } try { using (IsolatedStorageFile isolatedStorage = GetIsolatedStorageScope()) { string directoryName = "RaygunOfflineStorage"; if (isolatedStorage.DirectoryExists(directoryName)) { string[] fileNames = isolatedStorage.GetFileNames(directoryName + "\\*.txt"); foreach (string name in fileNames) { IsolatedStorageFileStream isoFileStream = isolatedStorage.OpenFile(directoryName + "\\" + name, FileMode.Open); using (StreamReader reader = new StreamReader(isoFileStream)) { string text = reader.ReadToEnd(); try { if (WebProxy != null) { WebClientHelper.WebProxy = WebProxy; } WebClientHelper.Send(text, _apiKey, ProxyCredentials); } catch { // If just one message fails to send, then don't delete the message, and don't attempt sending anymore until later. return; } System.Diagnostics.Debug.WriteLine("Sent " + name); } isolatedStorage.DeleteFile(directoryName + "\\" + name); } if (isolatedStorage.GetFileNames(directoryName + "\\*.txt").Length == 0) { System.Diagnostics.Debug.WriteLine("Successfully sent all pending messages"); isolatedStorage.DeleteDirectory(directoryName); } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error sending stored messages to Raygun.io due to: {ex}"); } } }
/// <summary> /// Posts a RaygunMessage to the Raygun.io api endpoint. /// </summary> /// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property /// set to a valid DateTime and as much of the Details property as is available.</param> public override void Send(RaygunMessage raygunMessage) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { string message = null; try { message = SimpleJson.SerializeObject(raygunMessage); } catch (Exception serializeException) { System.Diagnostics.Trace.WriteLine($"Error serializing Raygun message due to: {serializeException}"); if (RaygunSettings.Settings.ThrowOnError) { throw; } } if (message != null) { try { if (WebProxy != null) { WebClientHelper.WebProxy = WebProxy; } WebClientHelper.Send(message, _apiKey, ProxyCredentials); } catch (Exception sendMessageException) { try { System.Diagnostics.Trace.WriteLine($"Error sending exception to Raygun.io due to: {sendMessageException}"); // Attempt to store the message in isolated storage. SaveMessage(message); } catch (Exception saveMessageException) { // Ignored System.Diagnostics.Trace.WriteLine($"Error saving Raygun message due to: {saveMessageException}"); } if (RaygunSettings.Settings.ThrowOnError) { throw; } } SendStoredMessages(); } } }
/// <summary> /// Posts a RaygunMessage to the Raygun.io api endpoint. /// </summary> /// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property /// set to a valid DateTime and as much of the Details property as is available.</param> public override void Send(RaygunMessage raygunMessage) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { string message = null; try { message = SimpleJson.SerializeObject(raygunMessage); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error serializing exception {0}", ex.Message)); if (RaygunSettings.Settings.ThrowOnError) { throw; } } if (message != null) { try { if (WebProxy != null) { WebClientHelper.WebProxy = WebProxy; } WebClientHelper.Send(message, _apiKey, ProxyCredentials); } catch (Exception ex) { try { SaveMessage(message); Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); } catch { //ignored } if (RaygunSettings.Settings.ThrowOnError) { throw; } } SendStoredMessages(); } } }
private void Send(string message) { RaygunLogger.Instance.Verbose("Sending Payload --------------"); RaygunLogger.Instance.Verbose(message); RaygunLogger.Instance.Verbose("------------------------------"); if (WebProxy != null) { WebClientHelper.WebProxy = WebProxy; } WebClientHelper.Send(message, _apiKey, ProxyCredentials); }