I am implimenting Performance counters into a web application.
I use the following code to create the counters during setup:
private void SetupPerfCntrs( )
{
System.Diagnost ics.CounterCrea tionDataCollect ion CounterDatas = null;
System.Diagnost ics.CounterCrea tionData cdCounter4 = null;
try
{
if(System.Diagn ostics.Performa nceCounterCateg ory.Exists("Log isOnline"))
{
System.Diagnost ics.Performance CounterCategory .Delete("LogisO nline");
}
// Create a collection of type CounterCreation DataCollection.
CounterDatas = new System.Diagnost ics.CounterCrea tionDataCollect ion();
// Create the counters and set their properties.
cdCounter4 = new System.Diagnost ics.CounterCrea tionData();
cdCounter4.Coun terName = "PaymentsVi ew Response";
cdCounter4.Coun terHelp = "Time in millisecods for Payment View call to
respond";
cdCounter4.Coun terType =
System.Diagnost ics.Performance CounterType.Num berOfItems32;
// Add both counters to the collection.
CounterDatas.Ad d(cdCounter4);
// Create the category and pass the collection to it.
System.Diagnost ics.Performance CounterCategory .Create("LogisO nline", "Logis
Online Web Application Metrics", CounterDatas);
}
catch(Exception ex)
{
throw ex;
}
finally
{
CounterDatas = null;
cdCounter4 = null;
}
}
The code used to write to the performance counters are as follows:
Dim PCPaymentView As System.Diagnost ics.Performance Counter = New
System.Diagnost ics.Performance Counter("LogisO nline", "PaymentsVi ew Response",
"_Total", False)
Dim StartTime As DateTime = DateTime.Now