private static T CreateCounters <T>(string instance) { T result = Activator.CreateInstance <T>(); try { IICPerformanceCountersAttribute categoryAttr = AttributeHelper. GetAttribute <IICPerformanceCountersAttribute>(typeof(T)); List <IICPerformanceCounter> counters = new List <IICPerformanceCounter>(); FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (FieldInfo fieldInfo in fields) { IICPerformanceCounterAttribute counterAttr = AttributeHelper. GetAttribute <IICPerformanceCounterAttribute>(fieldInfo); IICPerformanceCounter perfCounter = new IICPerformanceCounter(); perfCounter._rawAttr = counterAttr; counters.Add(perfCounter); fieldInfo.SetValue(result, perfCounter); } IICPerformanceCounterMananger.CreateCounters(instance, categoryAttr, counters); } catch (Exception ex) { //SystemLog.Warn(LogEventID.PerformanceCounterFailed, ex, "PerformanceCounter<{0}>({1}) Create Failed.", typeof(T).Name, instance); } return(result); }
public static void GetCounters(IICPerformanceCounterCategory category, string instanceName) { IICPerformanceCounterMananger.CreateCounters(instanceName, category._categoryAttribute, category._counters); }