Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在尝试在asp net核心中配置metrics.net_C#_Asp.net Core_Metrics - Fatal编程技术网

C# 正在尝试在asp net核心中配置metrics.net

C# 正在尝试在asp net核心中配置metrics.net,c#,asp.net-core,metrics,C#,Asp.net Core,Metrics,我有一个asp.net核心web应用程序,我想使用metrics.net 在此之前,我按照以下方式配置度量和owin: Metric.Config .WithInternalMetrics() .WithOwin(中间件=>app.Use(中间件),config=>config .WithRequestMetricsConfig(c=>c.WithErrorsMeter() .WithActiveRequestCounter() .WithPostAndPutRequestSizeHistogr

我有一个asp.net核心web应用程序,我想使用metrics.net

在此之前,我按照以下方式配置度量和owin:

Metric.Config
.WithInternalMetrics()
.WithOwin(中间件=>app.Use(中间件),config=>config
.WithRequestMetricsConfig(c=>c.WithErrorsMeter()
.WithActiveRequestCounter()
.WithPostAndPutRequestSizeHistogram()
.WithRequestTimer()
,新[]{
新正则表达式(“(?i)^metrics”),
新正则表达式(“(?i)^health”),
新正则表达式(“(?i)^json”)
}
)
.WithMetricsEndpoint(endpointConfig=>
{
端点配置
.MetricsTextEndpoint(启用:false);
})
);

如何在asp net core中执行类似操作?

我们必须使用Microsoft.AspnetCore.Owin中的
app.UseOwin
包并将正确的中间件连接到管道

Metric.Config.WithInternalMetrics()
.WithOwin(中间件=>app.UseOwin(管道=>pipeline(下一步=>Engage(中间件,下一步))),config=>config
.WithRequestMetricsConfig(c=>c.WithAllOwinMetrics()
,新[]{
新正则表达式(“(?i)^metrics”),
新正则表达式(“(?i)^health”),
新正则表达式(“(?i)^json”)
}
)
.WithMetricsEndpoint(endpointConfig=>
{
端点配置
.MetricsJsonEndpoint(已启用:true)
.MetricsEndpoint(已启用:true)
.MetricsHealthEndpoint(已启用:true)
.MetricsTextEndpoint(已启用:false)
.MetricsPingEndpoint(启用:false);
})
);
啮合功能是这样的

private static Func Engage(动态中间件,Func next)
{
return env=>{
初始化(下一步);
返回middleware.Invoke(env);
};
}

Metrics.NET有很多功能。metrics中的API已按照.net core方法重新编写

Metric.net尚不支持dotnet core。您只能在完整框架下使用它。看这里@你可以让ASP.NET内核在(标准的.NET框架)上运行。使用Johan的回答,我成功地为Metrics.NET配置了OWIN适配器。非常感谢!