title: perfmon using EntLib - no instance in perfmon
body: <p>We are in need to add performance monitoring to our application.
  For the prototype I've created a sample project, which I'm trying to get into work.</p>
  
  <p>I'm trying to use policyInjection for the performance counters, so we'll be able to turn on and off the performance monitoring in the production environment.</p>
  
  <p>So far I can see the actual category in perfmon, but I cannot see any instances (see image), even I'm pretty sure the application is running and instance exists, as you can see in attached sources.</p>
  
  <p><img src="https://i.stack.imgur.com/lzQXe.png" alt="No instance in perfmon"></p>
  
  <p>I've tried a lot of things, also googled around, but didn't find any usable solution or clue what to look for.</p>
  
  <p>Application is created as consoleApplication</p>
  
  <p>You can also download a zipped project for VS here:
  <a href="http://dl.dropbox.com/u/19457132/stackOverflow/Mpd.Instrumentation.PerformanceCounter.zip" rel="nofollow noreferrer">http://dl.dropbox.com/u/19457132/stackOverflow/Mpd.Instrumentation.PerformanceCounter.zip</a></p>
  
  <p>Here are my sources.</p>
  
  <p><strong>Program.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Configuration.Install;
  using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
  using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
  using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Installers;
  
  namespace Mpd.Instrumentation.PerformanceCounter
  {
      class Program
      {
          static void Main(string[] args)
          {
             //RemoveCounters();   
             InstallCounters();
  
              MyCounters myCounter = PolicyInjection.Create&lt;MyCounters&gt;();
  
              for (int i = 0; i &lt; 100000000; i++)
              {
                  myCounter.SampleMethod(i);
              }
  
              Console.ReadLine();
          }
  
          public static void InstallCounters()
          {
              PerformanceCountersInstaller installer = new PerformanceCountersInstaller(new SystemConfigurationSource());
              IDictionary state = new Hashtable();
  
              installer.Context = new InstallContext();
              installer.Install(state);
              installer.Commit(state);
  
              Console.WriteLine("Performance counters have been successfully installed. Press enter to continue");
              Console.ReadLine();
          }
  
          private static void RemoveCounters()
          {
              PerformanceCountersInstaller installer = new PerformanceCountersInstaller(new SystemConfigurationSource());
              installer.Context = new InstallContext();
              installer.Uninstall(null);
              Console.WriteLine("Performance counters have been successfully removed. Press enter to continue.");
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p><strong>MyCounters.cs</strong></p>
  
  <pre><code>using System;
  using System.Threading;
  
  namespace Mpd.Instrumentation.PerformanceCounter
  {
      public class MyCounters : IPerformanceCounter
      {
          public void SampleMethod(int i)
          {
              Console.WriteLine(i);
              Thread.Sleep(50);
          }
      }
  }
  </code></pre>
  
  <p><strong>IPerformanceCounter.cs</strong></p>
  
  <pre><code>using System;
  
  namespace Mpd.Instrumentation.PerformanceCounter
  {
      public class IPerformanceCounter : MarshalByRefObject
      {
  
      }
  }
  </code></pre>
  
  <p>And finally <strong>app.config</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="policyInjection" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" /&gt;
      &lt;section name="instrumentationConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Configuration.InstrumentationConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;policyInjection&gt;
      &lt;policies&gt;
        &lt;add name="SampleCountersPolicy"&gt;
          &lt;matchingRules&gt;
            &lt;add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.MethodSignatureMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              match="SampleMethod" ignoreCase="true" name="Method Signature Matching Rule" /&gt;
          &lt;/matchingRules&gt;
          &lt;handlers&gt;
            &lt;add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.PerformanceCounterCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              categoryName=".aaaTest" instanceName="Default" useTotalCounter="true"
              incrementNumberOfCalls="true" incrementCallsPerSecond="true"
              incrementAverageCallDuration="true" incrementTotalExceptions="true"
              incrementExceptionsPerSecond="true" order="1" name="Performance Counter Call Handler" /&gt;
          &lt;/handlers&gt;
        &lt;/add&gt;
      &lt;/policies&gt;
    &lt;/policyInjection&gt;
    &lt;instrumentationConfiguration performanceCountersEnabled="true"
      applicationInstanceName="Default" /&gt;
  &lt;/configuration&gt;
  </code></pre>