Пример #1
0
        public HealthData CheckHealth()
        {
            _logger.Debug($"Check health for {_appName} started.");

            HealthData healthData = new HealthData(_appName);

            try
            {
                ConcurrentBag <HealthData> healthDataCollection = new ConcurrentBag <HealthData>();

                _healthDependencyCollection.AsParallel().ForAll(dep =>
                {
                    healthDataCollection.Add(dep.CheckHealth());
                });

                _logger.Debug($"Check health completed for {_appName}.");
                healthData.DependenciesStatus.AddRange(healthDataCollection);
                healthData.IsOK = true;
            }
            catch (Exception ex)
            {
                _logger.Error($"Check health crashed for {_appName}: {ex.Message}", ex);

                healthData.IsOK         = false;
                healthData.ErrorMessage = "HealthChecker crashed.";
            }

            _logger.Info($"Health check for {_appName} finished. Success: {healthData.IsOK}.");

            return(healthData);
        }