
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
466
|
Chapter 8: Diagnostics
PerformanceCounterCategory.Delete(categoryName);
}
PerformanceCounterCategory appCategory =
PerformanceCounterCategory.Create(categoryName, categoryHelp,
PerformanceCounterCategoryType.SingleInstance, counterCollection);
// Create the counter and initialize it.
PerformanceCounter appCounter =
new PerformanceCounter(categoryName, counterName, false);
appCounter.RawValue = 0;
return (appCounter);
}
Discussion
The first action this method takes is to create the CounterCreationDataCollection
object and CounterCreationData object. The CounterCreationData object is created
using the
counterName, counterHelp, and countertype parameters passed to the
CreateSimpleCounter method. The CounterCreationData object is then added to the
counterCollection.
The ASPNET user account, as well as many other user accounts by
default, prevent performance counters from being read. You can either
increase the permissions allowed for these accounts or use imperson-
ation with an account that has access to enable this functionality.
However, this then becomes a deployment requirement of your appli-
cation. Decreasing security for the
ASPNET account or other user
accounts may very well be frowned upon by IT folks deploying your
application.
If categoryName—a string containing the name