internal DefaultPerformanceCounters(ServiceHostBase serviceHost)
        {
            this.instanceName = DefaultPerformanceCounters.CreateFriendlyInstanceName(serviceHost);
            this.Counters     = new PerformanceCounter[(int)PerfCounters.TotalCounters];
            for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
            {
                try
                {
                    PerformanceCounter counter = PerformanceCounters.GetDefaultPerformanceCounter(this.perfCounterNames[i], this.instanceName);
                    if (counter != null)
                    {
                        this.Counters[i] = counter;
                    }
                    else
                    {
                        break;
                    }
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (DiagnosticUtility.ShouldTraceError)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCountersFailedForService,
                                                SR.GetString(SR.TraceCodePerformanceCountersFailedForService), null, e);
                    }
                    break;
                }
            }
        }
Exemple #2
0
 internal DefaultPerformanceCounters(ServiceHostBase serviceHost)
 {
     this.instanceName = CreateFriendlyInstanceName(serviceHost);
     this.Counters     = new PerformanceCounter[1];
     for (int i = 0; i < 1; i++)
     {
         try
         {
             PerformanceCounter defaultPerformanceCounter = PerformanceCounters.GetDefaultPerformanceCounter(this.perfCounterNames[i], this.instanceName);
             if (defaultPerformanceCounter != null)
             {
                 this.Counters[i] = defaultPerformanceCounter;
                 continue;
             }
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             if (DiagnosticUtility.ShouldTraceError)
             {
                 TraceUtility.TraceEvent(TraceEventType.Error, 0x8003b, System.ServiceModel.SR.GetString("TraceCodePerformanceCountersFailedForService"), null, exception);
             }
         }
         break;
     }
 }