예제 #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
        void InstallCounters()
        {
            if (counterConfigs != null)
            {
                CounterCreationDataCollection col = new CounterCreationDataCollection();

                foreach (PerfCounterConfig config in counterConfigs)
                {
                    CounterCreationData data = new CounterCreationData(config.Name, config.Help, config.CounterType);
                    col.Add(data);
                }
                try
                {
                    PerformanceCounterCategory.Create(Category, Help, CategoryType, col);
                }
                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 category '{0}': {1}\r\n{2}", Category,
                                                       ex.Message, ex.StackTrace));
                }
            }
        }