Does it actually work to use multiple versions of log4net via binding redirects?

时间:2015-07-13 21:10:55

标签: log4net

I tried this solution (https://stackoverflow.com/a/3163050/766964) to use two versions of log4net (1.2.10.0 and 1.2.13.0), and it did get me past the File Not Found exception, but then nothing is actually logged.

UPDATE: I got it to log by specifying the full type information:

<!--<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>-->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />

But does this work? Because shouldn't it use 1.2.13.0 section handler for that one? Is there a way to specify both handlers and two separate sections with the same name?

1 个答案:

答案 0 :(得分:1)

我认为您可以这样做,但您必须在代码中加载至少一个版本的配置。这篇文章应该有助Log4Net - Can I have a custom section name in Config。绑定工作的原因是因为您准确指定要使用的库(版本,公钥等)。绑定重定向仅在有问题的引用不明确时才启动(即找到相同程序集的两个版本)。在这里,您准确指定要使用的库。在回答原始问题时,是否可以指定2个具有相同名称的部分?是否可以更改其中一个部分的名称?显然不是,根据上面的链接。