RazorEngine TemplateServiceConfiguration is not compatible with log4net LogicalThreadStack

Since xUnit executes multiple threads parallel it is necessary to use the LogicalThreadContext from log4net to retrieve only the messages pertaining to the current test (any ideas of other methods of doing this are welcome).

Normally I have no problems with this setup but. Today I changed a test that uses RazorEngine to also use the solution below (before I filtered by the thread name an ID). It doesn't work anymore. Testing showed that the Problem is with the instantiation of the TemplateServiceConfiguration.

Does anyone know what is going on?

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);
    }

Update

The events are still there but the Properties property no longer contains the TestStack entry.

End update

Here is the constructor code for TemplateServiceConfiguration

    [SecuritySafeCritical]
    public TemplateServiceConfiguration()
    {
        Activator = new DefaultActivator();
        CompilerServiceFactory =
    #if RAZOR4
          new Roslyn.RoslynCompilerServiceFactory();
    #else
            new DefaultCompilerServiceFactory();
    #endif
        EncodedStringFactory = new HtmlEncodedStringFactory();

    #if !RAZOR4
    #pragma warning disable 0618 // Backwards Compat.
        CodeInspectors = new List<ICodeInspector>();
    #pragma warning restore 0618 // Backwards Compat.
    #endif

        ReferenceResolver = new UseCurrentAssembliesReferenceResolver();
        CachingProvider = new DefaultCachingProvider();
        TemplateManager =
            new DelegateTemplateManager();

        Namespaces = new HashSet<string>
                         {
                             "System", 
                             "System.Collections.Generic", 
                             "System.Linq"
                         };

        var config = RazorEngineConfigurationSection.GetConfiguration();
        Language = (config == null)
                       ? Language.CSharp
                       : config.DefaultLanguage;
    }