我公司的标准日志工具是NLog。我正在尝试引入Quartz.net,并被问及是否可以使用NLog而不是Log4Net。
我知道我可以重新编译以使用NLog,但如果可能的话,我想从配置文件中进行。
我公司的标准日志工具是NLog。我正在尝试引入Quartz.net,并被问及是否可以使用NLog而不是Log4Net。
我知道我可以重新编译以使用NLog,但如果可能的话,我想从配置文件中进行。
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
...
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/NLog.config" />
</factoryAdapter>
</logging>
</common>
</configuration>
使用配置指令确实是一种方法,但如果您已经有了现有的nlog配置,并且想要“插入”quartz日志记录,这是不必要的。
只需从nuget引用适当版本的'Common.Logging.NLog',按照通常的方式配置日志记录,并将其添加到末尾即可:
var config = new NameValueCollection();
var adaptor = new NLogLoggerFactoryAdapter(config);
Common.Logging.LogManager.Adapter = adaptor;
现在所有的石英日志(包括所有常见的日志)都将被转发到您现有的nlog配置中。
今天我遇到了同样的问题。这篇文章帮了我很多忙,但是有些东西已经改变了一点...
我使用的是Quartz.Net 2.6.1。
Common.Logging.NLog已经过时,每个NLog版本都有一个新的dll。
因此,新的配置如下:
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
...
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog21">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/NLog.config" />
</factoryAdapter>
</logging>
</common>
</configuration>
Common.Logging
Common.Logging.Core
Common.Logging.NLogXX