Пример #1
0
        public void InvalidCodeConfig_Tests()
        {
            var layout = new PatternLayout
            {
                ConversionPattern = "%date|%-5level|%message",
            };

            layout.ActivateOptions();

            {
                var appender = new SlackAppender
                {
                    SerializerType = typeof(JilHttpContentConverter),
                    Layout         = layout
                };

                Assert.Throws <LogException>(() => appender.ActivateOptions());
            }

            {
                var appender = new SlackAppender
                {
                    WebHookUrl = WebHookUrl,
                    Layout     = layout
                };

                Assert.Throws <LogException>(() => appender.ActivateOptions());
            }

            {
                var appender = new SlackAppender
                {
                    WebHookUrl     = WebHookUrl,
                    SerializerType = typeof(DummySerializer),
                    Layout         = layout
                };

                Assert.Throws <LogException>(() => appender.ActivateOptions());
            }
        }
Пример #2
0
        public void ValidCodeConfig_Tests()
        {
            var layout = new PatternLayout
            {
                ConversionPattern = "%date|%-5level|%message",
            };

            layout.ActivateOptions();

#if NETCOREAPP1_0 || NETCOREAPP1_1
            var repository = (Hierarchy)LogManager.CreateRepository(GetType().GetTypeInfo().Assembly, typeof(Hierarchy));
#else
            var repository = (Hierarchy)LogManager.CreateRepository(GetType().Assembly, typeof(Hierarchy));
#endif

            repository.Root.RemoveAllAppenders();

            var appender = new SlackAppender
            {
                WebHookUrl     = WebHookUrl,
                SerializerType = typeof(JilHttpContentConverter),
                Layout         = layout
            };

            appender.ActivateOptions();

            repository.Root.AddAppender(appender);

            BasicConfigurator.Configure(repository);

            var logger = LogManager.GetLogger(GetType());

            logger.Debug("log4net.validcode.debug");
            logger.Info("log4net.validcode.info");
            logger.Warn("log4net.validcode.warn");
            logger.Error("log4net.validcode.error");
            logger.Fatal("log4net.validcode.fatal");
        }