Exemplo n.º 1
0
        protected override void ConfigureHealthChecks(IHealthChecksBuilder healthChecksBuilder)
        {
            healthChecksBuilder.AddAsyncCheck("SqlServer", async() =>
            {
                var connectionString = new ProductsConfigurationProvider(Configuration).GetDatabaseConnectionString();

                using (var connection = new SqlConnection(connectionString))
                {
                    try
                    {
                        await connection.OpenAsync();

                        return(HealthCheckResult.Healthy());
                    }
                    catch (SqlException)
                    {
                        return(HealthCheckResult.Unhealthy());
                    }
                }
            });
        }