コード例 #1
0
 PerformanceCounter CounterFromConfig(string instance, PerfCounterConfig config)
 {
     try
     {
         PerformanceCounter counter;
         if (MultipleInstance)
         {
             if (instance == null)
             {
                 counter = new PerformanceCounter(Category, config.Name, ConfigUtility.ApplicationName, false);
             }
             else
             {
                 counter = new PerformanceCounter(Category, config.Name, instance, false);
             }
         }
         else
         {
             counter = new PerformanceCounter(Category, config.Name, false);
         }
         counter.RawValue = config.RawValue;
         return(counter);
     }
     catch (Exception ex)
     {
         //we'll log this latter, but we can't use handle exception now
         //  because we must be sure that it would be recursively
         LoggingWrapper.Write(string.Format("Failed to create counter '{0}': {1}\r\n{2}", config.Name,
                                            ex.Message, ex.StackTrace));
         return(null);
     }
 }
コード例 #2
0
        PerformanceCounter CounterFromConfig(PerfCounterConfig config)
        {
            PerformanceCounter counter;

            if (MultipleInstance)
            {
                counter = new PerformanceCounter(Category, config.Name, ConfigUtility.ApplicationName, false);
            }
            else
            {
                counter = new PerformanceCounter(Category, config.Name, false);
            }
            counter.RawValue = config.RawValue;
            return(counter);
        }