/// <summary> /// Returns the name of a <see cref="T:ExitGames.Diagnostics.Monitoring.CounterSetAttribute"/> or the <see cref="T:System.Reflection.MemberInfo"/> name combined with a parent counter set name. /// </summary> /// <param name="memberInfo">The member info.</param> /// <param name="counterSetAttribute">The counter set attribute.</param> /// <param name="parentCounterSetName">The parent counter set name.</param> /// <returns>The name of the <paramref name="counterSetAttribute"/> or the <paramref name="memberInfo"/> combined with <paramref name="parentCounterSetName"/>.</returns> private static string GetCounterSetName(MemberInfo memberInfo, CounterSetAttribute counterSetAttribute, string parentCounterSetName) { if (string.IsNullOrEmpty(counterSetAttribute.Name)) { return GetName(memberInfo.Name, parentCounterSetName); } return GetName(counterSetAttribute.Name, parentCounterSetName); }
/// <summary> /// Initializes a counter publisher. /// </summary> /// <param name="counterSamplePublisher">The counter publisher.</param> /// <param name="counterSet">An object providing counter instance members.</param> /// <param name="memberList">The member list.</param> /// <param name="counterSetName">Name of the counter set.</param> private static void InitializeCounterPublisher(CounterSamplePublisher counterSamplePublisher, object counterSet, IEnumerable<MemberInfo> memberList, string counterSetName) { foreach (var member in memberList) { PublishCounterAttribute attribute = GetCounterAttribute(member); if (attribute != null) { if (!IsCounterType(member)) { if (log.IsWarnEnabled) { log.WarnFormat("PublishCounterAttribute applied to member '{0}' which is not a ICounter type.", member.Name); } } else { ICounter counter = (ICounter)GetMemberValue(counterSet, member); if (counter == null) { if (log.IsWarnEnabled) { log.WarnFormat("Counter for member {0} has not been initialized.", member.Name); } } else if (counter.CounterType != CounterType.Undefined) { string name = GetCounterName(member, attribute, counterSetName); counterSamplePublisher.AddCounter(counter, name); if (log.IsDebugEnabled) { log.DebugFormat("Added counter '{0}' to counter publisher.", name); } } } } else { CounterSetAttribute attribute2 = GetCounterSetAttribute(member); if (attribute2 != null) { if (GetMemberValue(counterSet, member) == null) { if (log.IsWarnEnabled) { log.WarnFormat("CounterSet for member {0} has not been initialized.", member.Name); } } else { InitializeCounterPublisher(counterSamplePublisher, counterSet, GetCounterSetName(member, attribute2, counterSetName)); } } } } }