Exemplo n.º 1
0
        /// <summary>
        /// Tries to connect to the application's main database.
        /// </summary>
        public Task <HealthCheckItemResult> GetHealthCheckAsync()
        {
            var result = new HealthCheckItemResult(nameof(DatabaseHealthCheckProvider), SortOrder, "Checks the database", "Checks whether the main database can be accessed.");

            try
            {
                // Uncomment code below abd update it to match your DB context or make a direct SQL connection.
                //var context = new MyContext();
                //var item = await context.SomeSet.FirstAsync();
                //if (item != null)
                //{
                //    result.HealthState = HealthState.Healthy;
                //    result.Messages.Add("Successfully retrieved a record from the main database.");
                //}
                //else
                //{
                //    result.HealthState = HealthState.Unhealthy;
                //    result.Messages.Add("Connected to the database but could not find the requested record.");
                //}
            }
            catch
            {
                result.HealthState = HealthState.Unhealthy;
                result.Messages.Add("Error retrieving a record from the main database.");
            }
            return(Task.FromResult(result));
        }
        /// <summary>
        /// Returns the health heck info.
        /// </summary>
        public Task <HealthCheckItemResult> GetHealthCheckAsync()
        {
            var result = new HealthCheckItemResult(nameof(DiskSpaceHealthCheckProvider), SortOrder, "Checks disk space", $"Validates that the available disk space is more than {MinPercentageFree} percent.");

            try
            {
                var percentageFree = GetPercentageFree("C");
                result.HealthState = DetermineState(percentageFree);
                result.Messages.Add($"There is {(percentageFree > MinPercentageFree ? "more" : "LESS")} than {MinPercentageFree} percent available disk space.");
            }
            catch
            {
                result.HealthState = HealthState.Unhealthy;
                result.Messages.Add("Could not validate disk space.");
            }
            return(Task.FromResult(result));
        }