所以我正在创建几个自定义性能计数器并将它们分组到一个类别下。这是在 IIS 7 上托管并通过 Visual Studio 运行的 WCF 应用程序中构建的。
我一直在关注 msdn 的示例和文档here
这是我在方法中使用的代码:
if (PerformanceCounterCategory.Exists("MyCategory"))
{
PerformanceCounterCategory.Delete("MyCategory");
}
CounterCreationDataCollection counters = new CounterCreationDataCollection();
CounterCreationData getRequests = new CounterCreationData();
getRequests.CounterName = "Get count per sec";
getRequests.CounterHelp = "Get count per sec";
getRequests.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
counters.Add(getRequests);
CounterCreationData headRequests = new CounterCreationData();
headRequests.CounterName = "Head count per sec";
headRequests.CounterHelp = "Head count per sec";
headRequests.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
counters.Add(headRequests);
PerformanceCounterCategory.Create("MyCategory", "Custom Category", PerformanceCounterCategoryType.SingleInstance,counters);
我遇到的问题是最后一行给了我一个例外
System.dll 中出现“System.ComponentModel.Win32Exception”类型的未处理异常附加信息:参数不正确
编辑:
调用堆栈如下所示:
System.Diagnostics.PerformanceCounterLib.RegisterFiles(String arg0, Boolean unregister) at System.Diagnostics.PerformanceCounterLib.RegisterCategory(String categoryName, PerformanceCounterCategoryType categoryType, String categoryHelp, CounterCreationDataCollection creationData) at System.Diagnostics.PerformanceCounterCategory.Create(String categoryName, String categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData)
我想知道是否有人知道或见过这个问题?