C# Dot Net Core Mongo运行状况检查错误:新MongoClient can';不能加入词典

C# Dot Net Core Mongo运行状况检查错误:新MongoClient can';不能加入词典,c#,mongodb,.net-core,health-check,C#,Mongodb,.net Core,Health Check,我有一个用Dot Net Core 3.1编写的Web API应用程序,它对MongoDB进行了健康检查。我正在使用AspNetCore.HealthChecks.MongoDb(2.2.2)nuget进行Mongo健康检查。我们注意到,我们的生产日志中充斥着错误,称无法将新的MongoClient添加到字典中。你能帮忙吗 下面是MongoDB健康检查启动时编写的代码 public void ConfigureContainer(ServiceRegistry services) { se

我有一个用Dot Net Core 3.1编写的Web API应用程序,它对MongoDB进行了健康检查。我正在使用AspNetCore.HealthChecks.MongoDb(2.2.2)nuget进行Mongo健康检查。我们注意到,我们的生产日志中充斥着错误,称无法将新的MongoClient添加到字典中。你能帮忙吗

下面是MongoDB健康检查启动时编写的代码

public void ConfigureContainer(ServiceRegistry services)
{
   services.AddHealthChecks()
                .AddMongoDb(config.ConnectionStrings.MongoDbContext.ThrowIfNull("MongoDbContext"),
                            config.AppSettings.MongoDbName.ThrowIfNull("MongoDbName"), null, null, null);
}


public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
     app.UseHealthChecks("/api/v1.0/health", new HealthCheckOptions()
     {
        ResponseWriter = WriteResponse
     });
}

private static Task WriteResponse(HttpContext httpContext, HealthReport result)
{
       httpContext.Response.ContentType = "application/json";
       if (result.Status != HealthStatus.Healthy)
       {
                IReadOnlyDictionary<string, HealthReportEntry> healthResult = result.Entries;
                if (healthResult != null)
                {
                    string json = new JObject(healthResult.Select(pair =>
                            new JProperty(pair.Key, new JObject(
                                new JProperty("Status", pair.Value.Status.ToString()),
                                new JProperty("Description", pair.Value.Description?.ToString(CultureInfo.InvariantCulture)),
                                new JProperty("Exception", pair.Value.Exception?.ToString()
                                ))))).ToString(Formatting.Indented);
                    Log.Error("Error: {json}", json);
                    return httpContext.Response.WriteAsync($"{result.Status.ToString()} {Environment.NewLine} {json}");
                }
       }
       return httpContext.Response.WriteAsync(result.Status.ToString());
}
公共void配置容器(ServiceRegistry服务)
{
services.AddHealthChecks()
.AddMongoDb(config.connectionString.MongoDbContext.ThrowIfNull(“MongoDbContext”),
config.AppSettings.MongoDbName.ThrowIfNull(“MongoDbName”),null,null,null);
}
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
app.usehalthchecks(“/api/v1.0/health”),新的HealthCheckOptions()
{
ResponseWriter=WriteResponse
});
}
私有静态任务WriteResponse(HttpContext HttpContext,HealthReport结果)
{
httpContext.Response.ContentType=“应用程序/json”;
if(result.Status!=HealthStatus.health)
{
IReadOnlyDictionary healthResult=result.Entries;
如果(healthResult!=null)
{
字符串json=newjobject(healthResult.Select(pair=>
新JProperty(pair.Key,新作业对象(
新的JProperty(“Status”,pair.Value.Status.ToString()),
新的JProperty(“Description”,pair.Value.Description?.ToString(CultureInfo.InvariantCulture)),
新的JProperty(“异常”,pair.Value.Exception?.ToString()
))))).ToString(格式化.缩进);
Error(“Error:{json}”,json);
返回httpContext.Response.WriteAsync($“{result.Status.ToString()}{Environment.NewLine}{json}”);
}
}
返回httpContext.Response.WriteAsync(result.Status.ToString());
}

您在连接数据库时没有任何问题,对吗?@vasilisdmr没有,我在连接数据库时没有任何问题,并且应用程序正在按预期工作。唯一值得关注的是,应用程序在特定时间每天记录此错误10到15次