This post is based on my previous post on Getting started with Enterprise Library Performance Counters
Let’s assume you don’t want to use the config files to configure performance counters. You need to use the PerformanceCounterCallHandlers.
In order to achieve this, you need to follow the same steps - until step number 7, which I have stated in my previous post.
Step number 8 is different. Your config file will only contain the below.
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<section name="instrumentationConfiguration"type="Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Configuration.InstrumentationConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
eventLoggingEnabled="false" wmiEnabled="false" applicationInstanceName="" />
As you can see above, you can easily turn off the performance counters as a whole entity.
Now to add performance counters to a target method, you can simply use the PerformanceCounterCallHandler attribute as specified below.
[PerformanceCounterCallHandler("DemoCounters", "Operations Started/sec", IncrementCallsPerSecond = true)]
public void SampleMethod(int i)
Now you should see the similar results in Windows Performance Monitor as I stated in my previous post.
If you need to know more in PerformanceCounterCallHandler please refer to the below link