我想使用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);
}
}
谁知道我做错了什么?
TrackValue
不需要Metric
类的对象。 docs.microsoft.com/en-us/dotnet/api/…它需要一个数值,这就是你得到这个错误的原因。
发布者:@Chetan Ranpariya