/// <summary> /// Sends a transmission and handle errors. /// </summary> /// <param name="transmission">The transmission to send.</param> /// <param name="nextSendInterval">When this value returns it will hold a recommendation for when to start the next sending iteration.</param> /// <returns>A boolean value that indicates if there was a retriable error.</returns> protected virtual bool Send(StorageTransmission transmission, ref TimeSpan nextSendInterval) { try { if (transmission != null) { transmission.SendAsync().ConfigureAwait(false).GetAwaiter().GetResult(); // After a successful sending, try immeidiately to send another transmission. nextSendInterval = this.SendingInterval; } } catch (WebException e) { int?statusCode = GetStatusCode(e); nextSendInterval = this.CalculateNextInterval(statusCode, nextSendInterval, this.maxIntervalBetweenRetries); return(IsRetryable(statusCode, e.Status)); } catch (Exception e) { nextSendInterval = this.CalculateNextInterval(null, nextSendInterval, this.maxIntervalBetweenRetries); string msg = string.Format(CultureInfo.InvariantCulture, "Unknown exception during sending: {0}", e); CoreEventSource.Log.LogVerbose(msg); } return(false); }
/// <summary> /// Sends a transmission and handle errors. /// </summary> /// <param name="transmission">The transmission to send.</param> /// <param name="nextSendInterval">When this value returns it will hold a recommendation for when to start the next sending iteration.</param> /// <returns>A boolean value that indicates if there was a retriable error.</returns> protected virtual bool Send(StorageTransmission transmission, ref TimeSpan nextSendInterval) { try { if (transmission != null) { transmission.SendAsync().ConfigureAwait(false).GetAwaiter().GetResult(); // After a successful sending, try immeidiately to send another transmission. nextSendInterval = this.SendingInterval; } } // https://github.com/microsoft/ApplicationInsights-dotnet/blob/70e438848915ec163fd7794221b27be34260d3b4/BASE/src/Microsoft.ApplicationInsights/Channel/Transmission.cs#L158 // HttpClient.SendAsync throws HttpRequestException only on the following scenarios: // "The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout." // i.e for Server errors (500 status code), no exception is thrown. catch (HttpRequestException) { nextSendInterval = this.CalculateNextInterval(null, nextSendInterval, this.maxIntervalBetweenRetries); return(true); } catch (WebException e) { int?statusCode = GetStatusCode(e); nextSendInterval = this.CalculateNextInterval(statusCode, nextSendInterval, this.maxIntervalBetweenRetries); return(IsRetryable(statusCode, e.Status)); } catch (Exception e) { nextSendInterval = this.CalculateNextInterval(null, nextSendInterval, this.maxIntervalBetweenRetries); string msg = string.Format(CultureInfo.InvariantCulture, "Unknown exception during sending: {0}", e); CoreEventSource.Log.LogVerbose(msg); } return(false); }
/// <summary> /// Sends a transmission and handle errors. /// </summary> /// <param name="transmission">The transmission to send.</param> /// <param name="nextSendInterval">When this value returns it will hold a recommendation for when to start the next sending iteration.</param> /// <returns>A boolean value that indicates if there was a retriable error.</returns> protected virtual bool Send(StorageTransmission transmission, ref TimeSpan nextSendInterval) { try { if (transmission != null) { transmission.SendAsync().ConfigureAwait(false).GetAwaiter().GetResult(); // After a successful sending, try immeidiately to send another transmission. nextSendInterval = this.SendingInterval; } } catch (WebException e) { int? statusCode = GetStatusCode(e); nextSendInterval = this.CalculateNextInterval(statusCode, nextSendInterval, this.maxIntervalBetweenRetries); return IsRetryable(statusCode, e.Status); } catch (Exception e) { nextSendInterval = this.CalculateNextInterval(null, nextSendInterval, this.maxIntervalBetweenRetries); string msg = string.Format(CultureInfo.InvariantCulture, "Unknown exception during sending: {0}", e); CoreEventSource.Log.LogVerbose(msg); } return false; }