Antaris/RazorEngine

TemplateServiceConfiguration is not compatible with log4net LogicalThreadStack

Opened this issue · 0 comments

Normally this works:

        var mapp = new MemoryAppender();
        BasicConfigurator.Configure(mapp);

        ILog logger = LogManager.GetLogger("moduleX");
        using (log4net.LogicalThreadContext.Stacks["TestStack"].Push("context"))
        {
            logger.Warn("Something happened!");

            mapp.GetEvents().Where(x => (string)x.Properties["TestStack"] == "context").ToList().Count.ShouldBe(1);
        }

But as soon as I introduce a TemplateServiceConfiguration it does not:

        var mapp = new MemoryAppender();
        BasicConfigurator.Configure(mapp);

        ILog logger = LogManager.GetLogger("moduleX");
        using (log4net.LogicalThreadContext.Stacks["TestStack"].Push("context"))
        {
            logger.Warn("Something happened!");

            var tsc = new TemplateServiceConfiguration();

            logger.Warn("More happenings!");

            // assert now fails
            mapp.GetEvents().Where(x => (string)x.Properties["TestStack"] == "context").ToList().Count.ShouldBe(2);
        }

Does anyone know what could be going on here?

I use the LogicalThreadContext feature primarily in unit tests that run in parallel to get the right log events for the test function.