看看SpringFramework是如何解决这个问题的。它使用 Common.Logging,然后可以通过配置文件映射到 log4net 或任何其他自定义日志记录框架。您可以在Common.Logging 网站上找到更多详细信息,但基本上您需要执行以下操作:
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>
.... normal log4net configuration goes here...
</log4net>
Run Code Online (Sandbox Code Playgroud)
如果客户端也直接使用SpringFramework或Common.Logging,冲突仍然有可能,但发生的几率大大降低,原因如下: