Пример #1
0
        public void ForContext_with_non_null_argument_should_produce_a_wrapper_around_named_logger()
        {
            adapter = adapter.ForContext("CustomLogger");

            adapter.Info("Hello!");

            ObservedEvent.LoggerName.Should().Be("CustomLogger");
        }
Пример #2
0
        public void Log_method_should_render_trace_id()
        {
            adapter = new Log4netLog(log4netLogger, new Log4netLogSettings {UseVostokTemplate = true});

            adapter.WithProperty("traceContext", "guid").Info("Hello!");

            Output.Should().Be("guid Hello!");
        }
Пример #3
0
        public void ForContext_with_non_null_argument_should_render_context()
        {
            adapter = new Log4netLog(log4netLogger, new Log4netLogSettings {
                UseVostokTemplate = true
            })
                      .ForContext("CustomLogger");

            adapter.Info("Hello!");

            Output.Should().Be("[CustomLogger] Hello!");
        }
Пример #4
0
        public void ForContext_should_support_accumulating_logger_name_with_a_chain_of_calls()
        {
            adapter = adapter
                      .ForContext("CustomLogger1")
                      .ForContext("CustomLogger2")
                      .ForContext("CustomLogger3");

            adapter.Info("Hello!");

            ObservedEvent.LoggerName.Should().Be("CustomLogger1.CustomLogger2.CustomLogger3");
        }
Пример #5
0
        public void ForContext_should_support_accumulating_context_with_a_chain_of_calls()
        {
            adapter = new Log4netLog(log4netLogger, new Log4netLogSettings {
                UseVostokTemplate = true
            })
                      .ForContext("CustomLogger1")
                      .ForContext("CustomLogger2")
                      .ForContext("CustomLogger3");

            adapter.Info("Hello!");

            Output.Should().Be("[CustomLogger1 => CustomLogger2 => CustomLogger3] Hello!");
        }
Пример #6
0
        public void ForContext_should_preserve_configured_logger_name_factory()
        {
            ((Log4netLog)adapter).LoggerNameFactory = ctx => string.Join(".", ctx.Reverse());

            adapter = adapter
                      .ForContext("ctx1")
                      .ForContext("ctx2")
                      .ForContext("ctx3");

            adapter.Info("Hello!");

            ObservedEvent.LoggerName.Should().Be("ctx3.ctx2.ctx1");
        }
Пример #7
0
        public void ForContext_should_ignore_configured_logger_name_factory_on_render()
        {
            ((Log4netLog)adapter).LoggerNameFactory = ctx => string.Join(".", ctx.Reverse());

            adapter = new Log4netLog(log4netLogger, new Log4netLogSettings {
                UseVostokTemplate = true
            })
                      .ForContext("ctx1")
                      .ForContext("ctx2")
                      .ForContext("ctx3");

            adapter.Info("Hello!");

            Output.Should().Be("[ctx1 => ctx2 => ctx3] Hello!");
        }
Пример #8
0
        public void TestSetup()
        {
            outputBuilder = new StringBuilder();
            outputWriter = new StringWriter(outputBuilder);

            memoryAppender = new MemoryAppender();
            textAppender = new TextWriterAppender {Writer = outputWriter, Layout = new PatternLayout("%m")};

            log4netRepository = LogManager.GetAllRepositories().SingleOrDefault(x => x.Name == "test") ?? LogManager.CreateRepository("test");
            log4netRepository.ResetConfiguration();

            BasicConfigurator.Configure(log4netRepository, memoryAppender, textAppender);

            log4netLogger = LogManager.GetLogger("test", "root").Logger;

            adapter = new Log4netLog(log4netLogger);
        }