Я хочу применить проверки работоспособности из библиотеки AppMetrics в моем основном веб-приложении asp.net.Я пробовал несколько способов, но безуспешно.
В Program.cs
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseHealth()
.UseStartup<Startup>()
.Build();
В Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<HealthCheck, SampleHealthCheck>();
var metrics = new HealthBuilder()
.HealthChecks.AddCheck(new SampleHealthCheck())
.HealthChecks.AddCheck("DatabaseConnected",
() => new ValueTask<HealthCheckResult>(HealthCheckResult.Healthy("Database Connection OK")))
.HealthChecks.RegisterFromAssembly(services)
.Build();
services.AddHealth(metrics);
services.AddHealthEndpoints();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHealthAllEndpoints();
app.UseMvc();
}
Ошибка, которую я все еще получаювыглядит следующим образом:
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at at System.Reflection.RuntimeModule.GetDefinedTypes()
at at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at App.Metrics.Health.Extensions.DependencyInjection.Internal.DefaultHealthCheckTypeProvider.<>c.<get_HealthCheckTypes>b__5_0(Assembly a) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\Internal\DefaultHealthCheckTypeProvider.cs:25
at at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at App.Metrics.Health.Extensions.DependencyInjection.Internal.HealthChecksAsServices.AddHealthChecksAsServices(IServiceCollection services, IEnumerable`1 types) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\Internal\HealthChecksAsServices.cs:27
at App.Metrics.Health.Extensions.DependencyInjection.Internal.HealthChecksAsServices.AddHealthChecksAsServices(IServiceCollection services, IEnumerable`1 assemblies) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\Internal\HealthChecksAsServices.cs:53
at Microsoft.Extensions.DependencyInjection.ServiceCollectionHealthCheckBuilderExtensions.RegisterFromAssembly(IHealthCheckBuilder healthCheckBuilder, IServiceCollection services, DependencyContext dependencyContext) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\ServiceCollectionHealthCheckBuilderExtensions.cs:34
at Microsoft.AspNetCore.Hosting.HealthAspNetWebHostBuilderExtensions.<>c__DisplayClass5_0.<ConfigureHealth>b__0(WebHostBuilderContext context, IServiceCollection services) in C:\projects\aspnetcorehealth\src\App.Metrics.AspNetCore.Health.Hosting\HealthAspNetWebHostBuilderExtensions.cs:113
at at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
at at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at WebApiAppMetrics.Program.BuildWebHost(String[] args) in C:\DEV\AspnetWebApiAppMetricsPlayground\AspnetWebApiAppMetricsPlayground\WebApiAppMetrics\Program.cs:24
at WebApiAppMetrics.Program.Main(String[] args) in D:\_TEST_\AspnetWebApiAppMetricsPlayground\AspnetWebApiAppMetricsPlayground\WebApiAppMetrics\Program.cs:20