此問題被問到here,但該解決方案不是編程配置。在這種情況下,可以使用Common.Logging
正確配置庫Wrapper.dll
。控制檯應用程序ConsoleApplication1.exe
試圖實施Log4NetLoggerFactoryAdapter
。以編程方式配置Log4NetLoggerFactoryAdapter(重試)
This works fine,將日誌條目從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();
隨着編程解決方案,我可以成功地內ConsoleApplication1
使用GetLogger
從適配器或者或log4net
,但我不能讓日誌事件通過「Wrapper」庫中使用的記錄器傳播。
請注意,在工作正常我已經允許xml和註釋的編程調用。在不起作用我已經評論了相關的xml並實現了編程代碼。還要注意這是一個微不足道的例子。真正的應用程序正試圖使用一個.NET庫來實現Matlab的Common.Logging
。
完美。謝謝。 – mtech