请帮忙!无法添加性能计数器 - 禁用“添加”按钮

时间:2010-07-29 01:03:21

标签: enterprise-library

我使用Entlib 4.1创建了性能计数器,如下所示。当我打开performon.exe和添加计数器时 - 我可以看到我创建的性能对象和计数器列表。但是我无法添加它们,因为禁用了“添加”按钮。任何建议?

public class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("You are about to install the performance counters");
        InstallPerformaceCounters();
        Console.ReadLine();


        for (int i = 0; i < 100000; i++)
        {
            if (i % 3 == 2)
            {
                Thread.Sleep(100);
            }

            if (i % 5 == 2)
            {
                Thread.Sleep(1000);
            }

            PerformSearch(i);
        }

        Console.ReadLine();
    }

    private static void PerformSearch(int i)
    {
        Console.WriteLine(i);
    }

    private static void InstallPerformaceCounters()
    {
        try
        {
            PerformanceCountersInstaller installer = new PerformanceCountersInstaller(new SystemConfigurationSource());
            IDictionary state = new System.Collections.Hashtable();
            installer.Context = new InstallContext();
            installer.Install(state);
            installer.Commit(state);
            Console.WriteLine("Performance counters have been successfully installed.");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

////

的App.config

         <?xml version="1.0" encoding="utf-8"?>
         <configuration>
           <configSections>
              <section name="policyInjection"  type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
              <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
              <section name="instrumentationConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Configuration.InstrumentationConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         </configSections>
         <policyInjection>
            <policies>
              <add name="Search">
                    <handlers>
                       <add categoryName="Search Performance Counters" instanceName="Default"
        useTotalCounter="false" incrementNumberOfCalls="true" incrementCallsPerSecond="true"
        incrementAverageCallDuration="true" incrementTotalExceptions="true"
        incrementExceptionsPerSecond="true" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.PerformanceCounterCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Performance Counters Handler" />
                     </handlers>
              </add>
           </policies>
         </policyInjection>
     <instrumentationConfiguration performanceCountersEnabled="true"
eventLoggingEnabled="false" wmiEnabled="false" applicationInstanceName="" />
     </configuration>

1 个答案:

答案 0 :(得分:0)

这是我的错。我需要运行应用程序,特别是那些用这些计数器修饰的方法,所以我可以将计数器添加到列表中。