Пример #1
0
        public void Select(LoggerFilterOptions options, Type providerType, string category, out LogType logType,
                           out LogLevel?minLevel, out Func <string, string, LogLevel, bool> filter)
        {
            filter   = null;
            minLevel = options.MinLevel;
            logType  = options.MiniType;
            // Filter rule selection:
            // 1. Select rules for current logger type, if there is none, select ones without logger type specified
            // 2. Select rules with longest matching categories
            // 3. If there nothing matched by category take all rules without category
            // 3. If there is only one rule use it's level and filter
            // 4. If there are multiple rules use last
            // 5. If there are no applicable rules use global minimal level

            var providerAlias        = LoggerProviderAliasUtilities.GetAlias(providerType);
            LoggerFilterRule current = null;

            foreach (LoggerFilterRule rule in options.Rules)
            {
                if (IsBetter(rule, current, providerType.FullName, category) ||
                    (!string.IsNullOrEmpty(providerAlias) && IsBetter(rule, current, providerAlias, category)))
                {
                    current = rule;
                }
            }

            if (current != null)
            {
                filter   = current.Filter;
                minLevel = current.LogLevel;
                logType  = current.LogType;
            }
        }
        public void Select(LoggerFilterOptions options, Type providerType, string category, out LogType logType, out LogLevel?minLevel, out int traceCount, out Func <string, string, LogLevel, bool> filter)
        {
            filter     = null;
            minLevel   = new Microsoft.Extensions.Logging.LogLevel?(options.MinLevel);
            logType    = options.MiniType;
            traceCount = options.TraceCount;
            string           providerAlias = LoggerProviderAliasUtilities.GetAlias(providerType);
            LoggerFilterRule current       = null;

            foreach (LoggerFilterRule loggerFilterRule in options.Rules)
            {
                LoggerFilterRule rule = (LoggerFilterRule)loggerFilterRule;
                bool             flag = LoggerRuleSelector.IsBetter(rule, current, providerType.FullName, category) || (!string.IsNullOrEmpty(providerAlias) && LoggerRuleSelector.IsBetter(rule, current, providerAlias, category));
                if (flag)
                {
                    current = rule;
                }
            }
            bool flag2 = current != null;

            if (flag2)
            {
                filter     = current.Filter;
                minLevel   = current.LogLevel;
                logType    = current.LogType;
                traceCount = current.TraceCount;
            }
        }