public int GetThreshold(TelemetryActivationKind kind) { switch (kind) { case TelemetryActivationKind.Metric: return((int)Threshold.Metric); case TelemetryActivationKind.Textual: return((int)Threshold.Textual); } throw new ArgumentOutOfRangeException($"Invalid kind {kind}"); }
/// <summary> /// Determines whether the specified log level is active. /// </summary> /// <param name="level">The log level.</param> /// <returns> /// <c>true</c> if the specified log level is active; otherwise, <c>false</c>. /// </returns> private bool IsActive( int level, TelemetryActivationKind kind) { #region int minLevel = ... int minLevel; switch (kind) { case TelemetryActivationKind.Metric: minLevel = (int)_setting.Threshold.Metric; break; case TelemetryActivationKind.Textual: minLevel = (int)_setting.Threshold.Textual; break; default: throw new ArgumentOutOfRangeException($"invalid kind {kind}"); } #endregion // int minLevel = ... ActivationUnit setting = _setting; if (level < minLevel) { // Disable unless extends (setting.TextualThreshold) #region Check if pass the extends foreach (var extend in setting.Extends) { var extendLimit = extend.GetThreshold(kind); var tokenSupportAllFilters = extend.Filters.All(m => _activationContext.HasToken(m.Path)); if (tokenSupportAllFilters && extendLimit <= level) { return(true); } } return(false); #endregion // If(Extend) true } // Enable unless constrict (setting.TextualThreshold) #region Check if constricted foreach (var constrict in setting.Constricts) { var constrictLimit = constrict.GetThreshold(kind); var tokenSupportAllFilters = constrict.Filters.All(m => _activationContext.HasToken(m.Path)); if (tokenSupportAllFilters && constrictLimit > level) { return(false); // disable when (both level and filters match) } } #endregion // Check if constricted return(true); }