private ResourceMonitorEventArgs CreateVerificationEvent() { var evt = new ResourceMonitorEventArgs(); var timedOut = false; try { var source = new CancellationTokenSource(Configuration.Timeout); var verificationTask = _verificationStrategy.Check(source.Token); timedOut = !verificationTask .Wait(Configuration.Timeout) || source.Token.IsCancellationRequested; // It's up if it didn't timeout and the check was OK. evt.IsUp = !timedOut && verificationTask.Result; } catch (Exception ex) { evt.IsUp = false; evt.Exception = ex; } finally { if (timedOut) // To avoid throwing from the try block { evt.Exception = new TimeoutException(); } } return(evt); }
private void OnMonitoringEvent(ResourceMonitorEventArgs e) { try { MonitoringEvent?.Invoke(this, e); } catch (Exception ex) { _logger.LogCritical(0, ex, "The event handler has thrown an exception. The Exception will be re-thrown and the Monitoring will stop."); throw; } }