This week I have been extensively been working with Enterprise Library 5.0 .(Also called as EntLib) In most of the cases Enterprise Library works in the background and it is not always that clear about what’s happening under the hood. Well, this applied for me either this week. I’m using the Caching Application Block of Entlib and was curious about how this performed (how many items are there in the cache list, how many expirations occur, are expired items removed etc.)
First step I took was installing the EntLib instrumentation which can be installed by executing1 a .bat file which comes with the installation of Entlib.
1 Note that executing this batch file should be done with administrator privileges.
Actually I thought that this was it. All that I had to do was adding the counters in performance monitor (PerfMon) and see what happing under the hood. When I was trying to add the counters to PerfMon, I saw that the instrumentation installation has succeeded, because the counters where there.
But adding the counters was not possible. After some searches on the internet I found out that you have to enable performance counters in your application before you can add them to PerfMon to see what’s going on down there.
There are two ways of enabling your application to use performance counters. One is by using the configuration tool which is shipped with EntLib, or manually update your .config file with some references to EntLib dll’s and adding a configuration section. I’ll start with the first one, which is the easiest and is doing the adding part to the .config file for you.
Updating the .config file by use of the EntLib tool:
Start the EntLib configuration tool (Can be found under: All programs => Microsoft patterns & practices => Enterprise Library 5.0 => Enterprise Library Configuration) that fits to the .Net framework you’re using in your application. In my case that will be the X86 .Net 4.0 framework.
When the configuration tool is loaded, choose File => Open, navigate to your .config file and open it. Once it is opened, choose Blocks => Add Instrumentation Settings
Expand the Instrumentation settings block and set performanceCountersEnabled to true. Save the settings, so they will be written to your .config file. If you restart your application after saving, and then try to add a performance counter again, you will see that your process is added to the list of instances and that you’re able to add the counters.
Updating the .config file manually:
I can imagine that if you’re in the situation that you don’t have the configuration tool available to adjust your .config file (Like me on the production environment) you want to insert these settings manually. Below I will show you how and where to enter these settings in your config file to make this work.
The first step will be to open your .config file in your favorite (or the available) editor.
Now we have to add two parts to the config file. First one is the reference to EntLib to make sure the compiler knows what you mean when you say that you would like to enable the performance counters.
We do that by adding a new ConfigSection. Within this configsection we add a section where we reference the EntLib 5.0 resources like below.
1 <configSections> 2 <section name="instrumentationConfiguration" 3 type="Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Configuration.InstrumentationConfigurationSection, 4 Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 5 requirePermission="true" /> 6 </configSections>
The second part is setting the performance counters to enabled, which can be done with below code:
1 <instrumentationConfiguration performanceCountersEnabled="true" />
That is it! Pretty easy as you know how and where to configure it.