public static void HttpPing(this Core.ICakeContext context, string url, AliveSettings settings) { using (var alive = new Alive(context.Log)) { alive.HttpPing(url, settings); } }
public void HttpPing(string url, AliveSettings settings) { if (string.IsNullOrEmpty(url)) { throw new ArgumentException("Value cannot be null or empty.", nameof(url)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } try { if (settings.Timeout > 0) { _client.Timeout = TimeSpan.FromMilliseconds(settings.Timeout); } var sw = Stopwatch.StartNew(); var response = _client.GetAsync(url).Result; sw.Stop(); _log.Debug(response); if (response.IsSuccessStatusCode) { _log.Information($"{url} responded with {response.StatusCode:D} ({response.ReasonPhrase}) after {sw.ElapsedMilliseconds} ms"); return; } throw new NotAliveException($"The request to {url} failed with response status code {response.StatusCode:D} ({response.ReasonPhrase})"); } catch (AggregateException aggregateException) { ExceptionHandler.Handle(url, aggregateException); } }