// Returns true if the message can be sent, false if the sending is canceled. protected bool OnSendingMessage(RaygunMessage raygunMessage) { bool result = true; if (!_handlingRecursiveErrorSending) { EventHandler <RaygunSendingMessageEventArgs> handler = SendingMessage; if (handler != null) { RaygunSendingMessageEventArgs args = new RaygunSendingMessageEventArgs(raygunMessage); try { handler(this, args); } catch (Exception e) { // Catch and send exceptions that occur in the SendingMessage event handler. // Set the _handlingRecursiveErrorSending flag to prevent infinite errors. _handlingRecursiveErrorSending = true; Send(e); _handlingRecursiveErrorSending = false; } result = !args.Cancel; } } return(result); }
/// <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 void Send(RaygunMessage raygunMessage) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { using (var client = CreateWebClient()) { try { var message = SimpleJson.SerializeObject(raygunMessage); client.UploadString(RaygunSettings.Settings.ApiEndpoint, message); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); if (RaygunSettings.Settings.ThrowOnError) { throw; } } } } } }
protected async Task <string> OnCustomGroupingKey(Exception exception, RaygunMessage message) { string result = null; if (!_handlingRecursiveGrouping) { var handler = CustomGroupingKey; if (handler != null) { var args = new RaygunCustomGroupingKeyEventArgs(exception, message); try { handler(this, args); } catch (Exception e) { _handlingRecursiveGrouping = true; await SendAsync(e, null, null); _handlingRecursiveGrouping = false; } result = args.CustomGroupingKey; } } return(result); }
/// <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 void Send(RaygunMessage raygunMessage) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { string message = null; try { message = SimpleJson.SerializeObject(raygunMessage); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error serializing raygun message: {0}", ex.Message)); } if (message != null) { SendMessage(message); } } } }
private void Send(RaygunMessage raygunMessage, bool wait, bool exit) { if (ValidateApiKey() && !_exit) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { try { string message = SimpleJson.SerializeObject(raygunMessage); if (NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None) { SendMessage(message, wait, exit); } else { SaveMessage(message); } } catch (Exception ex) { Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); } } } }
/// <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 void Send(RaygunMessage raygunMessage) { if (ValidateApiKey()) { using (var client = new WebClient()) { client.Headers.Add("X-ApiKey", _apiKey); client.Encoding = System.Text.Encoding.UTF8; try { var message = SimpleJson.SerializeObject(raygunMessage); client.UploadString(RaygunSettings.Settings.ApiEndpoint, message); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); if (RaygunSettings.Settings.ThrowOnError) { throw; } } } } }
public async void Send(RaygunMessage raygunMessage) { HttpClientHandler handler = new HttpClientHandler { UseDefaultCredentials = true }; var client = new HttpClient(handler); { client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("raygun4net-winrt", "1.0.0")); HttpContent httpContent = new StringContent(SimpleJson.SerializeObject(raygunMessage)); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-raygun-message"); httpContent.Headers.Add("X-ApiKey", _apiKey); try { await PostMessageAsync(client, httpContent, RaygunSettings.Settings.ApiEndpoint); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); if (RaygunSettings.Settings.ThrowOnError) { throw; } } } }
private async Task SendOrSave(RaygunMessage raygunMessage) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { try { string message = SimpleJson.SerializeObject(raygunMessage); if (InternetAvailable()) { await SendMessage(message); } else { await SaveMessage(message); } } catch (Exception ex) { Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); } } } }
public string SaveCrashReport(RaygunMessage crashReport, int maxReportsStored) { try { // Can only save the report if we havnt reached the report count limit. if (IsFileLimitReached(Math.Min(maxReportsStored, MAX_STORED_REPORTS_UPPER_LIMIT))) { RaygunLogger.Warning("Failed to store crash report - Reached max crash reports stored on device"); return(null); } // Convert to JSON text. var reportJson = SimpleJson.SerializeObject(crashReport); // Generate a unique name for our report. var fileName = GetUniqueAcendingJsonName(); // Save the report to disk. return(StoreCrashReport(fileName, reportJson)); } catch (Exception ex) { RaygunLogger.Error(string.Format("Failed to store crash report - Error saving message to isolated storage {0}", ex.Message)); } return(null); }
protected bool CanSend(RaygunMessage message) { if (message != null && message.Details != null && message.Details.Response != null) { return(!_settings.ExcludedStatusCodes.Contains(message.Details.Response.StatusCode)); } return(true); }
/// <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(); } } }
// Returns true if the message can be sent, false if the sending is canceled. protected bool OnSendingMessage(RaygunMessage raygunMessage) { bool result = true; EventHandler <RaygunSendingMessageEventArgs> handler = SendingMessage; if (handler != null) { RaygunSendingMessageEventArgs args = new RaygunSendingMessageEventArgs(raygunMessage); handler(this, args); result = !args.Cancel; } return(result); }
/// <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 void Send(RaygunMessage raygunMessage) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { using (var client = new WebClient()) { client.Headers.Add("X-ApiKey", _apiKey); client.Encoding = System.Text.Encoding.UTF8; if (WebRequest.DefaultWebProxy != null) { Uri proxyUri = WebRequest.DefaultWebProxy.GetProxy(new Uri(RaygunSettings.Settings.ApiEndpoint.ToString())); if (proxyUri != null && proxyUri.AbsoluteUri != RaygunSettings.Settings.ApiEndpoint.ToString()) { client.Proxy = new WebProxy(proxyUri, false); if (ProxyCredentials == null) { client.UseDefaultCredentials = true; client.Proxy.Credentials = CredentialCache.DefaultCredentials; } else { client.UseDefaultCredentials = false; client.Proxy.Credentials = ProxyCredentials; } } } try { var message = SimpleJson.SerializeObject(raygunMessage); client.UploadString(RaygunSettings.Settings.ApiEndpoint, message); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); if (RaygunSettings.Settings.ThrowOnError) { throw; } } } } } }
/// <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) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { if (HasInternetConnection) { using (var client = new WebClient()) { client.Headers.Add("X-ApiKey", _apiKey); client.Headers.Add("content-type", "application/json; charset=utf-8"); client.Encoding = System.Text.Encoding.UTF8; try { var message = SimpleJson.SerializeObject(raygunMessage); client.UploadString(RaygunSettings.Settings.ApiEndpoint, message); System.Diagnostics.Debug.WriteLine("Sending message to Raygun.io"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); try { SaveMessage(SimpleJson.SerializeObject(raygunMessage)); System.Diagnostics.Debug.WriteLine("Exception has been saved to the device to try again later."); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(string.Format("Error saving Exception to device {0}", e.Message)); } } } } else { try { var message = SimpleJson.SerializeObject(raygunMessage); SaveMessage(message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error saving Exception to device {0}", ex.Message)); } } } } }
/// <summary> /// Posts a RaygunMessage to the Raygun 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 async Task Send(RaygunMessage raygunMessage) { if (!ValidateApiKey()) { return; } bool canSend = OnSendingMessage(raygunMessage) && CanSend(raygunMessage); if (!canSend) { return; } var requestMessage = new HttpRequestMessage(HttpMethod.Post, _settings.ApiEndpoint); requestMessage.Headers.Add("X-ApiKey", _apiKey); try { var message = SimpleJson.SerializeObject(raygunMessage); requestMessage.Content = new StringContent(message, Encoding.UTF8, "application/json"); var result = await Client.SendAsync(requestMessage); if (!result.IsSuccessStatusCode) { Debug.WriteLine($"Error Logging Exception to Raygun {result.ReasonPhrase}"); if (_settings.ThrowOnError) { throw new Exception("Could not log to Raygun"); } } } catch (Exception ex) { Debug.WriteLine($"Error Logging Exception to Raygun {ex.Message}"); if (_settings.ThrowOnError) { throw; } } }
private void Send(RaygunMessage raygunMessage, int timeout) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { string message = null; try { message = SimpleJson.SerializeObject(raygunMessage); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error serializing message {0}", ex.Message)); } if (message != null) { try { SaveMessage(message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error saving Exception to device {0}", ex.Message)); if (HasInternetConnection) { SendMessage(message, timeout); } } // In the case of sending messages during a crash, only send stored messages if there are 2 or less. // This is to prevent keeping the app open for a long time while it crashes. if (HasInternetConnection && GetStoredMessageCount() <= 2) { SendStoredMessages(timeout); } } } } }
/// <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 { Send(message); } catch (Exception ex) { SaveMessage(message); System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); 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) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { string message = null; try { message = SimpleJson.SerializeObject(raygunMessage); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error serializing message {0}", ex.Message)); } if (message != null) { try { SaveMessage(message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error saving Exception to device {0}", ex.Message)); if (HasInternetConnection) { SendMessage(message); } } if (HasInternetConnection) { 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) { if (ValidateApiKey()) { bool canSend = OnSendingMessage(raygunMessage); if (canSend) { string message = null; try { message = SimpleJson.SerializeObject(raygunMessage); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error Serializing Exception {0}", ex.Message)); } if (!String.IsNullOrWhiteSpace(message)) { using (var client = new WebClient()) { client.Headers.Add("X-ApiKey", _apiKey); client.Headers.Add("content-type", "application/json; charset=utf-8"); client.Encoding = System.Text.Encoding.UTF8; try { client.UploadString(RaygunSettings.Settings.ApiEndpoint, message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); } } } } } }
/// <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 void Send(RaygunMessage raygunMessage) { if (ValidateApiKey()) { if (HasInternetConnection) { using (var client = new WebClient()) { client.Headers.Add("X-ApiKey", _apiKey); client.Encoding = System.Text.Encoding.UTF8; try { var message = SimpleJson.SerializeObject(raygunMessage); client.UploadString(RaygunSettings.Settings.ApiEndpoint, message); System.Diagnostics.Debug.WriteLine("Sending message to Raygun.io"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message)); } } } else { try { var message = SimpleJson.SerializeObject(raygunMessage); SaveMessage(message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error saving Exception to device {0}", ex.Message)); } } } }
private RaygunMessageBuilder() { _raygunMessage = new RaygunMessage(); }
/// <summary> /// Asynchronously transmits a message to Raygun.io. /// </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 void SendInBackground(RaygunMessage raygunMessage) { ThreadPool.QueueUserWorkItem(c => Send(raygunMessage)); }
/// <summary> /// Posts a RaygunMessage to the Raygun 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) { if (!ValidateApiKey()) { RaygunLogger.Instance.Warning("Failed to send error report due to invalid API key."); return; } bool canSend = OnSendingMessage(raygunMessage); if (!canSend) { return; } string message = null; try { message = SimpleJson.SerializeObject(raygunMessage); } catch (Exception ex) { RaygunLogger.Instance.Error($"Failed to serialize report due to: {ex.Message}"); if (RaygunSettings.Settings.ThrowOnError) { throw; } } if (string.IsNullOrEmpty(message)) { return; } bool successfullySentReport = true; try { Send(message); } catch (Exception ex) { successfullySentReport = false; RaygunLogger.Instance.Error($"Failed to send report to Raygun due to: {ex.Message}"); SaveMessage(message); if (RaygunSettings.Settings.ThrowOnError) { throw; } } if (successfullySentReport) { SendStoredMessages(); } }
private RaygunMessageBuilder(RaygunSettingsBase settings) { _raygunMessage = new RaygunMessage(); _settings = settings; }
protected RaygunMessageBuilderBase() { _raygunMessage = new RaygunMessage(); }
/// <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 void Send(RaygunMessage raygunMessage) { bool calledFromUnhandled = IsCalledFromApplicationUnhandledExceptionHandler(); Send(raygunMessage, calledFromUnhandled, false); }
/// <summary> /// Asynchronously transmits a message to Raygun. /// </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 Task SendInBackground(RaygunMessage raygunMessage) { return(Task.Run(() => Send(raygunMessage))); }
protected virtual bool CanSend(RaygunMessage message) { return(true); }
/// <summary> /// Posts a RaygunMessage to the Raygun 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 abstract void Send(RaygunMessage raygunMessage);