这个问题在这里被问到,但是解决方案不是程序化配置。在这种情况下,库Wrapper.dll
已正确配置为Common.Logging
. 控制台应用程序ConsoleApplication1.exe
尝试实现Log4NetLoggerFactoryAdapter
.
这工作正常Wrapper.dll
,从控制台发送日志条目。
app.config
:_
<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.Log4Net1211">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>... a valid ConsoleAppender ..</log4net>
内的代码ConsoleApplication1
:
//var properties = new Common.Logging.Configuration.NameValueCollection();
//properties.Add("configType", "INLINE");
//var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
var c1 = new Wrapper();
这不起作用。它不会将日志条目发送Wrapper.dll
到控制台。app.config
:_
<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.Log4Net1211">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common> -->
<log4net>... a valid ConsoleAppender ..</log4net>
内的代码ConsoleApplication1
:
var properties = new Common.Logging.Configuration.NameValueCollection();
properties.Add("configType", "INLINE");
var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
var c1 = new Wrapper();
使用编程解决方案,我可以从适配器或从成功使用GetLogger
,ConsoleApplication1
但log4net
我无法从“包装器”库中使用的记录器中传播日志事件。
请注意,在工作正常的情况下,我已允许 xml 并评论了编程调用。在不起作用我已经注释了相关的 xml 并实现了编程代码。另请注意,这是一个简单的示例。真正的应用程序正在尝试使用Common.Logging
从 Matlab 实现的 .NET 库。