Пример #1
0
        // constructors

        public TelnetLoggerProvider(IServiceProvider serviceProvider, Func <string, LogLevel, bool> filter, bool includeScopes)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            this.filter   = filter;
            this.settings = new TelnetLoggerSettings()
            {
                IncludeScopes = includeScopes,
            };

            this.serviceProvider = serviceProvider;
        }
Пример #2
0
        public TelnetLoggerProvider(IServiceProvider serviceProvider, ITelnetLoggerSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.settings        = settings;
            this.serviceProvider = serviceProvider;

            if (this.settings.ChangeToken != null)
            {
                this.settings.ChangeToken.RegisterChangeCallback(this.OnConfigurationReload, null);
            }
        }
Пример #3
0
        // methods

        private void OnConfigurationReload(object state)
        {
            // The settings object needs to change here, because the old one is probably holding on
            // to an old change token.
            this.settings = this.settings.Reload();

            foreach (var logger in this.loggers.Values)
            {
                logger.Filter        = GetFilter(logger.Name, this.settings);
                logger.IncludeScopes = this.settings.IncludeScopes;
            }

            // The token will change each time it reloads, so we need to register again.
            if (this.settings?.ChangeToken != null)
            {
                this.settings.ChangeToken.RegisterChangeCallback(this.OnConfigurationReload, null);
            }
        }
Пример #4
0
        private Func <string, LogLevel, bool> GetFilter(string name, ITelnetLoggerSettings settings)
        {
            if (this.filter != null)
            {
                return(this.filter);
            }

            if (settings != null)
            {
                foreach (var prefix in GetKeyPrefixes(name))
                {
                    LogLevel level;

                    if (settings.TryGetSwitch(prefix, out level))
                    {
                        return((n, l) => l >= level);
                    }
                }
            }

            return((n, l) => false);
        }
        public static ILoggerFactory AddTelnet(this ILoggerFactory factory, IServiceProvider serviceProvider, ITelnetLoggerSettings settings)
        {
            factory.AddProvider(new TelnetLoggerProvider(serviceProvider, settings));

            return(factory);
        }