public async Task <string> GetStatus() { IHealthCheckService[] monitoredServices = new IHealthCheckService[] { _healthService }; // Check for all services so we can log the status of all failures rather than // than just the first one. bool allHealthy = true; //Select an async callback that keeps the name with the service. var healthChecks = monitoredServices.Select(async svc => new { Status = await svc.IsHealthy() }); var results = await Task.WhenAll(healthChecks); foreach (var result in results) { if (!result.Status) { allHealthy = false; _logger.LogError("Service not healthy."); } } if (!allHealthy) { _logger.LogError("One or more services are not healthy."); throw new APIErrorException(500, "One or more services are not healthy."); } return(HEALTHY_STATUS); }