JSON serializable object representing the configuration of the logging subsystem. May be passed to LogManager.Configure.
コード例 #1
0
        public void GetSection_NullFactoryAdapter_ThrowsConfigurationException()
        {
            var config = new LogConfiguration();

            var reader = new LogConfigurationReader(config);

            Assert.Throws<ConfigurationException>(() => reader.GetSection(null));
        }
コード例 #2
0
        public void GetSection_NullFactoryAdapter_ThrowsConfigurationException()
        {
            var config = new LogConfiguration();

            var reader = new LogConfigurationReader(config);

            Assert.Throws <ConfigurationException>(() => reader.GetSection(null));
        }
コード例 #3
0
        /// <summary>
        /// Creates a new <see cref="LogConfigurationReader"/> given a <see cref="LogConfiguration"/> object.
        /// </summary>
        /// <param name="configuration"><see cref="LogConfiguration"/> to be parsed.</param>
        public LogConfigurationReader(LogConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _configuration = configuration;
        }
コード例 #4
0
        /// <summary>
        /// Creates a new <see cref="LogConfigurationReader"/> given a <see cref="LogConfiguration"/> object.
        /// </summary>
        /// <param name="configuration"><see cref="LogConfiguration"/> to be parsed.</param>
        public LogConfigurationReader(LogConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _configuration = configuration;
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: net-commons/common-logging
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();
            Configuration = builder.Build();

            var logConfiguration = new LogConfiguration();
            Configuration.GetSection("LogConfiguration").Bind(logConfiguration);
            LogManager.Configure(logConfiguration);
        }
コード例 #6
0
        public void GetSection_BadFactoryAdapterType_ThrowsConfigurationException()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type = "SomeType, SomeAssembly"
                }
            };

            var reader = new LogConfigurationReader(config);

            Assert.Throws <ConfigurationException>(() => reader.GetSection(null));
        }
コード例 #7
0
        public void GetSection_EmptyFactoryAdapterType_ThrowsConfigurationException()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type = ""
                }
            };

            var reader = new LogConfigurationReader(config);

            Assert.Throws<ConfigurationException>(() => reader.GetSection(null));
        }
コード例 #8
0
        public void GetSection_GoodFactoryAdapterType_ReturnsLogSettingWithType()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type = typeof(FakeFactoryAdapter).AssemblyQualifiedName
                }
            };

            var reader = new LogConfigurationReader(config);

            var result = reader.GetSection(null) as LogSetting;

            Assert.NotNull(result);
            Assert.AreEqual(typeof(FakeFactoryAdapter), result.FactoryAdapterType);
        }
コード例 #9
0
        public void GetSection_NoArguments_ReturnsLogSettingWithNullArguments()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type = typeof(FakeFactoryAdapter).AssemblyQualifiedName
                }
            };

            var reader = new LogConfigurationReader(config);

            var result = reader.GetSection(null) as LogSetting;

            Assert.NotNull(result);
            Assert.IsNull(result.Properties);
        }
コード例 #10
0
        public void GetSection_HasArguments_ReturnsLogSettingWithArguments()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type      = typeof(FakeFactoryAdapter).AssemblyQualifiedName,
                    Arguments = new NameValueCollection
                    {
                        { "arg1", "value1" }
                    }
                }
            };

            var reader = new LogConfigurationReader(config);

            var result = reader.GetSection(null) as LogSetting;

            Assert.NotNull(result);
            Assert.AreEqual("value1", result.Properties["arg1"]);
        }
コード例 #11
0
        public void GetSection_GoodFactoryAdapterType_ReturnsLogSettingWithType()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type = typeof(FakeFactoryAdapter).AssemblyQualifiedName
                }
            };

            var reader = new LogConfigurationReader(config);

            var result = reader.GetSection(null) as LogSetting;

            Assert.NotNull(result);
            Assert.AreEqual(typeof(FakeFactoryAdapter), result.FactoryAdapterType);
        }
コード例 #12
0
        public void GetSection_HasArguments_ReturnsLogSettingWithArguments()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type = typeof(FakeFactoryAdapter).AssemblyQualifiedName,
                    Arguments = new NameValueCollection
                    {
                        { "arg1", "value1" }
                    }
                }
            };

            var reader = new LogConfigurationReader(config);

            var result = reader.GetSection(null) as LogSetting;

            Assert.NotNull(result);
            Assert.AreEqual("value1", result.Properties["arg1"]);
        }
コード例 #13
0
        public void GetSection_NoArguments_ReturnsLogSettingWithNullArguments()
        {
            var config = new LogConfiguration()
            {
                FactoryAdapter = new FactoryAdapterConfiguration()
                {
                    Type = typeof(FakeFactoryAdapter).AssemblyQualifiedName
                }
            };

            var reader = new LogConfigurationReader(config);

            var result = reader.GetSection(null) as LogSetting;

            Assert.NotNull(result);
            Assert.IsNull(result.Properties);
        }