Exemplo n.º 1
0
        private void SetupActionNullRaisesArgumentNullException()
        {
            Action <LogstashOptions> nullAction = null;
            var ex = Assert.Throws <ArgumentNullException>(() => LogstashOptionsReader.Read(nullAction));

            Assert.Equal("setupAction", ex.ParamName);
        }
        private void OptionsNullRaisesArgumentNullException()
        {
            IConfiguration nullConfig = null;
            var            ex         = Assert.Throws <ArgumentNullException>(() => LogstashOptionsReader.Read(nullConfig));

            Assert.Equal("config", ex.ParamName);
        }
        private void MinimumLevelNullSetsToMinimum()
        {
            var config = TestOptionsFactory.CreateMemoryConfig("myApp", "http://localhost", "index", null);

            var options = LogstashOptionsReader.Read(config);

            Assert.Equal(0, (int)options.MinimumLevel);               // the levels are changed in RC2, so this test will probably need to be updated
        }
Exemplo n.º 4
0
        private void IndexWhitespaceRaisesInvalidOptionException()
        {
            var setupAction = TestOptionsFactory.CreateSetupAction("myApp", "http://localhost", "  ", LogLevel.Information);

            var ex = Assert.Throws <InvalidOptionException>(() => LogstashOptionsReader.Read(setupAction));

            Assert.Equal(Defaults.ConfigKeys.Index, ex.OptionKey);
            Assert.Equal("  ", ex.OptionValue);
        }
Exemplo n.º 5
0
        private void InvalidUriRaisesInvalidOptionException()
        {
            var setupAction = TestOptionsFactory.CreateSetupAction("myApp", "abcde", "index", LogLevel.Information);

            var ex = Assert.Throws <InvalidOptionException>(() => LogstashOptionsReader.Read(setupAction));

            Assert.Equal(Defaults.ConfigKeys.Url, ex.OptionKey);
            Assert.Equal("abcde", ex.OptionValue);
        }
Exemplo n.º 6
0
        private void AppIdNullRaisesInvalidOptionException()
        {
            var setupAction = TestOptionsFactory.CreateSetupAction(null, "http://localhost", "index", LogLevel.Information);

            var ex = Assert.Throws <InvalidOptionException>(() => LogstashOptionsReader.Read(setupAction));

            Assert.Equal(Defaults.ConfigKeys.AppId, ex.OptionKey);
            Assert.Equal("(null)", ex.OptionValue);
        }
        private void IndexWhitespaceRaisesInvalidOptionException()
        {
            var config = TestOptionsFactory.CreateMemoryConfig("myApp", "http://localhost", "  ", LogLevel.Error);

            var ex = Assert.Throws <InvalidOptionException>(() => LogstashOptionsReader.Read(config));

            Assert.Equal(Defaults.ConfigKeys.Index, ex.OptionKey);
            Assert.Equal("  ", ex.OptionValue);
        }
        private void InvalidUriRaisesInvalidOptionException()
        {
            var config = TestOptionsFactory.CreateMemoryConfig("myApp", "abcdefg", "index", LogLevel.Error);

            var ex = Assert.Throws <InvalidOptionException>(() => LogstashOptionsReader.Read(config));

            Assert.Equal(Defaults.ConfigKeys.Url, ex.OptionKey);
            Assert.Equal("abcdefg", ex.OptionValue);
        }
        private void AppIdNullRaisesInvalidOptionException()
        {
            var config = TestOptionsFactory.CreateMemoryConfig(null, "http://localhost", "index", LogLevel.Error);

            var ex = Assert.Throws <InvalidOptionException>(() => LogstashOptionsReader.Read(config));

            Assert.Equal(Defaults.ConfigKeys.AppId, ex.OptionKey);
            Assert.Equal("(null)", ex.OptionValue);
        }
Exemplo n.º 10
0
        private void MinimumLevelNullSetsToMinimum()
        {
            var logstashOptions = LogstashOptionsReader.Read(options =>
            {
                options.AppId = "myApp";
                options.Url   = "http://localhost";
                options.Index = "index";
            });

            Assert.Equal(0, (int)logstashOptions.MinimumLevel);               // the levels are changed in RC2, so this test will probably need to be updated
        }
        /// <summary>
        /// Adds the Logstash HTTP Provider to the ASP.NET logging framework.
        /// </summary>
        /// <param name="app">The ApplicationBuilder.</param>
        /// <param name="config">An IConfiguration instance that contains the Logstash HTTP provider's options.</param>
        /// <returns>The LoggerFactory.</returns>
        public static ILoggerFactory AddLogstashHttp(this ILoggerFactory factory, IApplicationBuilder app, IConfiguration config)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app), $"{nameof(app)} cannot be null.");
            }
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config), $"{nameof(config)} cannot be null.");
            }

            var options  = LogstashOptionsReader.Read(config);
            var provider = new LogstashHttpLoggerProvider(app.ApplicationServices, options);

            factory.AddProvider(provider);
            return(factory);
        }