示例#1
0
        public void CanUseCustomPrefixToConfigureSettings()
        {
            const string prefix1 = "custom1";
            const string prefix2 = "custom2";

            // Make sure we have the expected keys in the App.config
            Assert.Equal("Warning", ConfigurationManager.AppSettings[prefix1 + ":serilog:minimum-level"]);
            Assert.Equal("Error", ConfigurationManager.AppSettings[prefix2 + ":serilog:minimum-level"]);

            var log1 = new LoggerConfiguration()
                       .WriteTo.Observers(o => { })
                       .ReadFrom.AppSettings(prefix1)
                       .CreateLogger();

            var log2 = new LoggerConfiguration()
                       .WriteTo.Observers(o => { })
                       .ReadFrom.AppSettings(prefix2)
                       .CreateLogger();

            Assert.False(log1.IsEnabled(LogEventLevel.Information));
            Assert.True(log1.IsEnabled(LogEventLevel.Warning));

            Assert.False(log2.IsEnabled(LogEventLevel.Warning));
            Assert.True(log2.IsEnabled(LogEventLevel.Error));
        }
示例#2
0
        public void CanUseCustomSettingDelimiterToConfigureSettings()
        {
            const string prefix1 = "|";
            const string prefix2 = "!";

            // Make sure we have the expected keys in the App.config
            Assert.AreEqual("Warning", ConfigurationManager.AppSettings["serilog|minimum-level"]);
            Assert.AreEqual("Error", ConfigurationManager.AppSettings["serilog!minimum-level"]);

            var log1 = new LoggerConfiguration()
               .WriteTo.Observers(o => { })
               .ReadFrom.AppSettings(null,prefix1)
               .CreateLogger();

            var log2 = new LoggerConfiguration()
                .WriteTo.Observers(o => { })
                .ReadFrom.AppSettings(null,prefix2)
                .CreateLogger();

            Assert.IsFalse(log1.IsEnabled(LogEventLevel.Information));
            Assert.IsTrue(log1.IsEnabled(LogEventLevel.Warning));

            Assert.IsFalse(log2.IsEnabled(LogEventLevel.Warning));
            Assert.IsTrue(log2.IsEnabled(LogEventLevel.Error));
        }
        public void CanUseCustomPrefixToConfigureSettings()
        {
            const string prefix1 = "custom1";
            const string prefix2 = "custom2";

            var log1 = new LoggerConfiguration()
                       .WriteTo.Observers(o => { })
                       .ReadFrom.AppSettings(prefix1, filePath: GetConfigPath())
                       .CreateLogger();

            var log2 = new LoggerConfiguration()
                       .WriteTo.Observers(o => { })
                       .ReadFrom.AppSettings(prefix2, filePath: GetConfigPath())
                       .CreateLogger();

            Assert.False(log1.IsEnabled(LogEventLevel.Information));
            Assert.True(log1.IsEnabled(LogEventLevel.Warning));

            Assert.False(log2.IsEnabled(LogEventLevel.Warning));
            Assert.True(log2.IsEnabled(LogEventLevel.Error));
        }
示例#4
0
        internal void SetConfiguration(LoggerConfiguration newConfiguration)
        {
            this.configuration = newConfiguration;

            // pre-calculate 'enabled' flags
            this.isTraceEnabled = newConfiguration.IsEnabled(LogLevel.Trace);
            this.isDebugEnabled = newConfiguration.IsEnabled(LogLevel.Debug);
            this.isInfoEnabled  = newConfiguration.IsEnabled(LogLevel.Info);
            this.isWarnEnabled  = newConfiguration.IsEnabled(LogLevel.Warn);
            this.isErrorEnabled = newConfiguration.IsEnabled(LogLevel.Error);
            this.isFatalEnabled = newConfiguration.IsEnabled(LogLevel.Fatal);

            OnLoggerReconfigured(EventArgs.Empty);
        }
示例#5
0
        internal void SetConfiguration(LoggerConfiguration newConfiguration)
        {
            _configuration = newConfiguration;

            //LogLevel 的一些设置
            _isTraceEnabled = newConfiguration.IsEnabled(LogLevel.Trace);
            _isDebugEnabled = newConfiguration.IsEnabled(LogLevel.Debug);
            _isInfoEnabled  = newConfiguration.IsEnabled(LogLevel.Info);
            _isWarnEnabled  = newConfiguration.IsEnabled(LogLevel.Warn);
            _isErrorEnabled = newConfiguration.IsEnabled(LogLevel.Error);
            _isFatalEnabled = newConfiguration.IsEnabled(LogLevel.Fatal);

            OnLoggerReconfigured(EventArgs.Empty);
        }
示例#6
0
        internal void SetConfiguration(LoggerConfiguration newConfiguration)
        {
            this.configuration = newConfiguration;

            // pre-calculate 'enabled' flags
            this.isTraceEnabled = newConfiguration.IsEnabled(LogLevel.Trace);
            this.isDebugEnabled = newConfiguration.IsEnabled(LogLevel.Debug);
            this.isInfoEnabled  = newConfiguration.IsEnabled(LogLevel.Info);
            this.isWarnEnabled  = newConfiguration.IsEnabled(LogLevel.Warn);
            this.isErrorEnabled = newConfiguration.IsEnabled(LogLevel.Error);
            this.isFatalEnabled = newConfiguration.IsEnabled(LogLevel.Fatal);

            var loggerReconfiguredDelegate = this.LoggerReconfigured;

            if (loggerReconfiguredDelegate != null)
            {
                loggerReconfiguredDelegate(this, new EventArgs());
            }
        }