如何对性能计数器类别进行版本控制?
我有一个性能计数器类别。此类别中的计数器可能会在我的下一个版本中发生变化,因此当程序启动时,我想检查该类别是否存在以及它是否是正确的版本 - 如果不存在,则创建新类别。我可以通过在帮助字符串中存储 GUID 来做到这一点,但这显然很臭。是否可以使用 .NET API 更干净地完成此操作?
现有的臭版本...
if (PerformanceCounterCategory.Exists(CATEGORY_NAME))
{
PerformanceCounterCategory c = new PerformanceCounterCategory(CATEGORY_NAME);
if (c.CategoryHelp != CATEGORY_VERSION)
{
PerformanceCounterCategory.Delete(CATEGORY_NAME);
}
}
if (!PerformanceCounterCategory.Exists(CATEGORY_NAME))
{
// Create category
}
I have a performance counter category. The counters in this category may change for my next release so when the program starts, I want to check if the category exists and it is the correct version - if not, create the new category. I can do this by storing a GUID in the help string but this is obviously smelly. Is it possible to do this more cleanly with the .NET API?
Existing smelly version...
if (PerformanceCounterCategory.Exists(CATEGORY_NAME))
{
PerformanceCounterCategory c = new PerformanceCounterCategory(CATEGORY_NAME);
if (c.CategoryHelp != CATEGORY_VERSION)
{
PerformanceCounterCategory.Delete(CATEGORY_NAME);
}
}
if (!PerformanceCounterCategory.Exists(CATEGORY_NAME))
{
// Create category
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我们的系统中,每次应用程序启动时,我们都会检查现有类别。如果未找到,我们将创建该类别。如果存在,我们会将现有类别与我们期望的类别进行比较,如果存在缺失值,则重新创建它(删除、创建)。
In our system, each time the application starts we do a check for the existing category. If it isn't found, we create the category. If it exists, we compare the existing category to what we expect and recreate it (delete, create) if there are missing values.
我认为没有更好的方法。恕我直言,我不认为这是一个糟糕的解决方案。
I don't think there is a better way. IMHO, I don't think this is a terrible solution.