我公司的标准日志记录工具是 NLog。我正在尝试介绍 Quartz.net,并被问到是否可以使用 NLog 而不是 Log4Net。
我知道我可以重新编译以使用 NLog,但如果可能的话,我想从配置文件中进行。
我公司的标准日志记录工具是 NLog。我正在尝试介绍 Quartz.net,并被问到是否可以使用 NLog 而不是 Log4Net。
我知道我可以重新编译以使用 NLog,但如果可能的话,我想从配置文件中进行。
假设您使用的是 Quartz.net 1.0.3。您必须添加对以下程序集的引用:
Common.Logging
Common.Logging.NLog
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.config 文件。
注意:
Quartz.net 使用 Common.Logging 1.2 版。
使用配置指令当然是这样做的一种方式,但如果你有一个现有的 nlog 配置并且只想“放入”石英日志记录,那就没有必要了。
只需从 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>
NLogLoggerFactoryAdapter的命名空间没有改变,但是 dll 名称改变了。
确保您拥有相同版本的:
Common.Logging
Common.Logging.Core
Common.Logging.NLogXX