问题描述
在此处提出了此问题,但是解决方案不是编程配置.在这种情况下,库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();
使用编程解决方案,我可以从适配器或log4net
在ConsoleApplication1
中成功使用GetLogger
,但是我无法从包装器"库中使用的记录器中传播日志事件. /p>
请注意,在正常工作中,我允许使用xml并注释了编程调用.在不起作用中,我注释了相关的xml并实现了程序代码.还请注意,这是一个简单的示例.真正的应用程序正在尝试使用从Matlab实现Common.Logging
的.NET库.
在创建适配器后,必须将其设置为:
var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
Common.Logging.LogManager.Adapter = adapter;
var c1 = new Wrapper();
This question was asked here, however the solution was not a programmatic configuration. In this case, a library Wrapper.dll
is properly configured with Common.Logging
. A console application ConsoleApplication1.exe
attempts to implement a Log4NetLoggerFactoryAdapter
.
This works fine, sending log entries from Wrapper.dll
to the console.
The 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>
The code within ConsoleApplication1
:
//var properties = new Common.Logging.Configuration.NameValueCollection();
//properties.Add("configType", "INLINE");
//var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
var c1 = new Wrapper();
This does not work. It does not send log entries from Wrapper.dll
to the console.The 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>
The code within ConsoleApplication1
:
var properties = new Common.Logging.Configuration.NameValueCollection();
properties.Add("configType", "INLINE");
var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
var c1 = new Wrapper();
With the programmatic solution I can successfully use GetLogger
within ConsoleApplication1
from either the adapter or from log4net
, but I cannot get the log events to propagate through from the loggers used in the "Wrapper" library.
Note that in works fine I have allowed the xml and commented the programmatic invocation. In does not work I have commented the relevant xml and implemented the programmatic code. Note also that this is a trivial example. The real application is trying to use a .NET library that implements Common.Logging
from Matlab.
After you create the adapter you have to set it as the LogManager's Adapter:
var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
Common.Logging.LogManager.Adapter = adapter;
var c1 = new Wrapper();
这篇关于以编程方式配置Log4NetLoggerFactoryAdapter(重试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!