private bool IsEnabled(ITelemetry item)
        {
            bool enabled = true;

            if (item is ISupportProperties telemetry && _filterOptions != null)
            {
                if (!telemetry.Properties.TryGetValue(LogConstants.CategoryNameKey, out string categoryName))
                {
                    // If no category is specified, it will be filtered by the default filter
                    categoryName = string.Empty;
                }

                // Extract the log level and apply the filter
                if (telemetry.Properties.TryGetValue(LogConstants.LogLevelKey, out string logLevelString) &&
                    Enum.TryParse(logLevelString, out LogLevel logLevel))
                {
                    LoggerFilterRule filterRule = _ruleMap.GetOrAdd(categoryName, SelectRule(categoryName));

                    if (filterRule.LogLevel != null && logLevel < filterRule.LogLevel)
                    {
                        enabled = false;
                    }
                    else if (filterRule.Filter != null)
                    {
                        enabled = filterRule.Filter(ProviderType.FullName, categoryName, logLevel);
                    }
                }
            }

            return(enabled);
        }
示例#2
0
        private bool IsEnabled(ITelemetry item)
        {
            bool enabled = true;

            if (item is ISupportProperties telemetry && _filterOptions != null)
            {
                if (!telemetry.Properties.TryGetValue(LogConstants.CategoryNameKey, out string categoryName))
                {
                    // If no category is specified, it will be filtered by the default filter
                    categoryName = string.Empty;

                    // WebJobs host does many internal calls, polling queues and blobs, etc...
                    // we do not want to report all of them by default, but only those which are relevant for
                    // function execution: bindings and user code (which have category and level stamped on the telemetry).
                    // So, if there is no category on the operation telemtery (request or dependency),
                    // it won't be tracked unless filter explicitly enables it
                    if (telemetry is OperationTelemetry)
                    {
                        enabled = false;
                    }
                }

                // Extract the log level and apply the filter
                if (telemetry.Properties.TryGetValue(LogConstants.LogLevelKey, out string logLevelString) &&
                    Enum.TryParse(logLevelString, out LogLevel logLevel))
                {
                    LoggerFilterRule filterRule = _ruleMap.GetOrAdd(categoryName, SelectRule(categoryName));

                    if (filterRule.LogLevel != null && logLevel < filterRule.LogLevel)
                    {
                        enabled = false;
                    }
                    else if (filterRule.Filter != null)
                    {
                        enabled = filterRule.Filter(ProviderType.FullName, categoryName, logLevel);
                    }
                }
            }

            return(enabled);
        }
示例#3
0
        internal bool IsEnabled(string category, LogLevel logLevel)
        {
            LoggerFilterRule filterRule = SelectRule(category, _loggerFilterOptions);

            if (filterRule.LogLevel != null && logLevel < filterRule.LogLevel)
            {
                return(false);
            }
            if (filterRule.Filter != null)
            {
                bool enabled = filterRule.Filter(ProviderType.FullName, category, logLevel);
                if (!enabled)
                {
                    return(false);
                }
            }
            if (filterRule.LogLevel != null)
            {
                return(Utilities.DefaultLoggingFilter(category, logLevel, filterRule.LogLevel.Value, filterRule.LogLevel.Value));
            }
            return(Utilities.DefaultLoggingFilter(category, logLevel, _loggingFilterHelper.UserLogDefaultLogLevel, _loggingFilterHelper.SystemLogDefaultLogLevel));
        }