c# - 跟踪指标值应用程序洞察错误?
问题描述
我想用 nameList 和 valueList 跟踪指标,但是在运行单元测试时会显示下一个错误:
$exception {System.ArgumentException:无法处理指定的值。应为数值,但指定的 metricValue 是 Microsoft.ApplicationInsights.Metric 类型。您是否指定了正确的指标配置?
这是我的代码:
private void CreateMetric(String metricName, double Amount, List<Property> additionalProperties)
{
List<String> metrycsNameList = new List<String>();
List<String> metrycsValueList = new List<String>();
try
{
additionalProperties.ForEach(property => metrycsValueList.Add(property.Value));
additionalProperties.ForEach(property => metrycsNameList.Add(property.Name));
Metric metric = _client.GetMetric(new MetricIdentifier("MetricNamespace", metricName, metrycsNameList));
AddMetricValues(metric, metrycsValueList);
}
catch (Exception ex)
{
throw new CustomMetricException("CustomMetricException", "Error adding a Custom Metric", ex.StackTrace);
}
}
// Checking dimension of the list (up to 10) and adding metrics.
private void AddMetricValues(Metric metric, List<String> metrycsValueList)
{
int numberOfElements = metrycsValueList.Count;
switch (numberOfElements)
{
case 1:
metric.TrackValue(metric, metrycsValueList[0]);
break;
case 2:
metric.TrackValue(metric, metrycsValueList[0], metrycsValueList[1]);
break;
case 3:
metric.TrackValue(metric, metrycsValueList[0], metrycsValueList[1], metrycsValueList[2]);
break;
...
}
这就是我用列表调用方法的方式:
public void AddCustomMetricTestTupla()
{
List<Property> propertiesList = new List<Property>();
propertiesList.Add(new Property("propertyExample", "value"));
propertiesList.Add(new Property("propertyExample1", "value2"));
propertiesList.Add(new Property("propertyExample2", "value3"));
//Tests method AddCustomMetric giving a tuple as a param.
using (AzureInsightsClient azureInsightsClient = new AzureInsightsClient(myClientKey))
{
azureInsightsClient.FlushMetrics();
azureInsightsClient.AddCustomMetric("Example", 2, propertiesList);
}
}
有人知道我在做什么错吗?
解决方案
推荐阅读
- javascript - VueJS Axios,如何从数组中获取数据
- asp.net-mvc - 使用登录名抓取 Web 应用程序 (ASP.net)
- clearcase - 如果我希望我的符号链接在主(或开发)视图上变为活动状态,我需要签入吗?
- java - Spring JPA 基础存储库
- algorithm - 哪种隐写方法适合这个问题?
- c - 如何使用 SDL2 创建每像素 1 位的曲面
- jenkins - 如何将可选的 Jenkins 参数传递到 Jenkinsfile
- c# - 如何在 Unity 中检测 Tilemap Colliders 和 2D box colliders 之间的碰撞
- sql - SQL 查找不完整的记录集
- itext - Itext 5 - 分离签名 - getRangeStream() 返回的变量 byte[]