How do I switch from Log4Net to NLog in Quartz.Net?
Asked Answered
T

3

8

My company's standard logging tool is NLog. I'm trying to introduce Quartz.net and was asked if it could use NLog instead of Log4Net.

I know I can recompile to use NLog, but I'd like to do it from the configuration files if at all possible.

Thermosphere answered 4/7, 2011 at 10:1 Comment(0)
C
10

Assuming that you're using Quartz.net 1.0.3. you have to add a reference to the following assemblies:

Common.Logging
Common.Logging.NLog
NLog

Then you have to add the following configuration in your application's config file:

<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>

Note that I am using an external NLog.config file.

NOTE:

Quartz.net uses Common.Logging version 1.2.

Carruthers answered 4/7, 2011 at 10:22 Comment(2)
That worked great! Thanks. Just a note for future readers. Make sure that ALL of the DLLs get copied to the correct folder.Thermosphere
Just in case someone wants just one Common.Logging version in his/her project, I've recompiled Quartz with 2.0 just like a breeze. Download the sources, replace the binaries and recompile.Sauerbraten
S
4

The use of config directives is certainly one way of doing this, but if you have an existing nlog config and want to just 'drop in' the quartz logging, it's unnecessary.

Simply reference 'Common.Logging.NLog' of the appropriate version from nuget, configure your logging as normal and add this to the end:

var config = new NameValueCollection();
var adaptor = new NLogLoggerFactoryAdapter(config);
Common.Logging.LogManager.Adapter = adaptor;

All of the quartz logging (and all common logging) will now be forwarded to your existing nlog configuration.

Sesterce answered 13/12, 2016 at 3:30 Comment(0)
V
3

Today I'm facing with the same issue. This article help me a lot, but thigs are changed a little bit...

I use Quartz.Net 2.6.1.

Common.Logging.NLog is deprecated and there is a new dll for each NLog version.

So the new configs is:

<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>

The namespace of NLogLoggerFactoryAdapter is not changed, but the dll name is changed.

Be sure you have the same version of:

  • Common.Logging

  • Common.Logging.Core

  • Common.Logging.NLogXX

Vauntcourier answered 24/4, 2018 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.