Esempio n. 1
0
        public void MethodNameCategoryTest()
        {
            CategoryTraceListener categoryTraceListener = new CategoryTraceListener();

            Trace.Listeners.Clear();
            Trace.Listeners.Add(categoryTraceListener);

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            AppenderTrace traceAppender = new AppenderTrace();
            LayoutPattern methodLayout  = new LayoutPattern("%method");

            methodLayout.Activate();
            traceAppender.Category = methodLayout;
            traceAppender.Layout   = new LayoutLoggerSimple();
            traceAppender.Activate();

            BasicConfig.Config(rep, traceAppender);

            ILog log = LogManager.Get(rep.Name, GetType());

            log.Debug("Message");

            Assert.AreEqual(
                System.Reflection.MethodInfo.GetCurrentMethod().Name,
                categoryTraceListener.Category);
        }
Esempio n. 2
0
        public void NamedPatternConverterWithPrecision2ShouldStripLessLeadingStuffIfPresent()
        {
            StringAppender stringAppender = new StringAppender();
            LayoutPattern  layout         = NewPatternLayout();

            layout.AddConverter("message-as-name", typeof(MessageAsNamePatternConverter));
            layout.Pattern = "%message-as-name{2}";
            layout.Activate();
            stringAppender.Layout = layout;
            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            BasicConfig.Config(rep, stringAppender);
            ILog log1 = LogManager.Get(rep.Name, "TestAddingCustomPattern");

            log1.Info("NoDots");
            Assert.AreEqual("NoDots", stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();

            log1.Info("One.Dot");
            Assert.AreEqual("One.Dot", stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();

            log1.Info("Tw.o.Dots");
            Assert.AreEqual("o.Dots", stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();

            log1.Info("TrailingDot.");
            Assert.AreEqual("TrailingDot.", stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();

            log1.Info(".LeadingDot");
            Assert.AreEqual("LeadingDot", stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();

            // empty string and other evil combinations as tests for of-by-one mistakes in index calculations
            log1.Info(string.Empty);
            Assert.AreEqual(string.Empty, stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();

            log1.Info("x");
            Assert.AreEqual("x", stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();

            log1.Info(".");
            Assert.AreEqual(".", stringAppender.GetString(), "%message-as-name not registered");
            stringAppender.Reset();
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a logger hierarchy, configures a SMTP pickup dir appender and returns an ILogger
        /// </summary>
        /// <param name="appender">The appender to use</param>
        /// <returns>A configured ILogger</returns>
        private ILogger CreateLogger(AppenderSmtpPickup appender)
        {
            ILoggerController h = LogManager.CreateController("TestRepository");

            LayoutPattern layout = new LayoutPattern();

            layout.Pattern = "%m%n";
            layout.Activate();

            appender.Layout = layout;
            appender.Activate();

            h.Root.AddAppender(appender);
            h.Initialize();

            ILogger log = h.Get("Logger");

            return(log);
        }
Esempio n. 4
0
        public void TestAddingCustomPattern()
        {
            StringAppender stringAppender = new StringAppender();
            LayoutPattern  layout         = NewPatternLayout();

            layout.AddConverter("TestAddingCustomPattern", typeof(TestMessagePatternConverter));
            layout.Pattern = "%TestAddingCustomPattern";
            layout.Activate();

            stringAppender.Layout = layout;

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            BasicConfig.Config(rep, stringAppender);

            ILog log1 = LogManager.Get(rep.Name, "TestAddingCustomPattern");

            log1.Info("TestMessage");
            Assert.AreEqual("TestMessage", stringAppender.GetString(), "%TestAddingCustomPattern not registered");
            stringAppender.Reset();
        }