Turn off Debug Logging in Quartz .Net
Asked Answered
V

6

24

I am using Quartz.NET for scheduling some custom tasks in our application. Everything works fine except that it logs about twenty debug entries in one second.

I don't know how to turn off the debug logging. Any help would be really appreciated as I have been trying to lookup in the net with no luck.

The debug entries look like the below

DEBUG 2009-05-12 03:24:14,000 8612670ms StdRowLockSemaphore    ObtainLock         - Lock 'TRIGGER_ACCESS' is desired by: SchedulerFactory_QuartzSchedulerThread
DEBUG 2009-05-12 03:24:14,029 8612699ms StdRowLockSemaphore    ExecuteSQL         - Lock 'TRIGGER_ACCESS' is being obtained: SchedulerFactory_QuartzSchedulerThread
DEBUG 2009-05-12 03:24:14,029 8612699ms StdRowLockSemaphore    ObtainLock         - Lock 'TRIGGER_ACCESS' given to: SchedulerFactory_QuartzSchedulerThread
DEBUG 2009-05-12 03:24:14,034 8612704ms StdRowLockSemaphore    ReleaseLock        - Lock 'TRIGGER_ACCESS' returned by: SchedulerFactory_QuartzSchedulerThread
DEBUG 2009-05-12 03:24:14,035 8612705ms StdRowLockSemaphore    ObtainLock         - Lock 'TRIGGER_ACCESS' is desired by: SchedulerFactory_QuartzSchedulerThread
DEBUG 2009-05-12 03:24:14,035 8612705ms JobRunShell            Run                - Calling Execute on job DEFAULT.ProcessIncomingMTRJob
Vagal answered 18/5, 2009 at 11:15 Comment(0)
C
7

Quartz.net uses Common.Logging, so something like this in your App.config/Web.config:

<configSections>
    <sectionGroup name="common">
        <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
</configSections>

<common>
    <logging>
        <factoryAdapter type="Common.Logging.Simple.**youradapterhere**, Common.Logging">
            <arg key="level" value="ERROR" />
        </factoryAdapter>
    </logging>
</common>

Be sure to change the youradapterhere to the actual logging adapter you're using, or NoOpLoggerFactoryAdapter if you want to disable logging entirely.


** Edit: ** Based on Ganesh's comment:

<sectionGroup name="common"> 
    <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/> 
</sectionGroup> 
<common>  
    <logging>  
        <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">  
            <arg key="configType" value="INLINE"/>  
            <arg key="configFile" value="filename"/>  
            <arg key="level" value="ERROR" /> <!-- add this line here -->
        </factoryAdapter>  
    </logging> 
</common>

** Edit 2: **

For the benefits of those who don't want to read the comments, the log level was actually set in the log4net root config:

<log4net>
    <root>
        <level value="DEBUG" /> <!-- This is the value that needed changing -->
        <appender-ref ref="Console" />
        <appender-ref ref="RollingFile" />
    </root>
</log4net>
Crigger answered 18/5, 2009 at 11:30 Comment(8)
We are already using the Common.Logging in our ASP .Net application. The entry in the web.config looks as below. Can you help me out as to where do i add the entry you suggested <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/> </sectionGroup> <common> <logging> <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"> <arg key="configType" value="INLINE"/> <arg key="configFile" value="filename"/> </factoryAdapter> </logging> </common>Vagal
I edited my answer with your config and added the relevant line.Crigger
We are also logging info from the component which Quartz .net invokes as a scheduled job. Is it possible to specify multiple values in the key <arg key="level" value="ERROR" /> <!-- add this line here --> Will this be possible <arg key="level" value="ERROR, INFO, WARN" /> Thanks for all your helpVagal
Log4Net docs say the following: "A log request of level L in a logger with (either assigned or inherited, whichever is appropriate) level K, is enabled if L >= K. This rule is at the heart of log4net. It assumes that levels are ordered. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL." The way I interpret that is, if you set loglevel to INFO, you will also get all messages from levels WARN, ERROR and FATAL. So you should replace ERROR with INFO in my example.Crigger
As per your advice i added the specified line to the web.config at the recommended position, but Quartz .Net is still printing the DEBUG log messages. The line I added is <arg key="level" value="INFO" /> Any idea as to why it is not working?Vagal
Do you have any appender-specific configurations that would have a <level value="DEBUG" /> setting in the config file?Crigger
The root tag, configuration is <level value="All"/> and I changed it to <level value="INFO"/> Quartz.Net has stopped the Debug logging but it still logs, minimum of about 5 Info entries per second. Is there a way to control the logging from the jobs.xml file which configures the triggers and schedule for Quartz .Net?Vagal
Not that I know of. Taking a quick peek at some of the sources, it looks like the logging is configured by level, not by action, so I suspect your best bet is just specifying a different log level.Crigger
D
27

Rytmis' answer is great if you want to reduce all your logging which goes through the Common Logging Infrastructure.

But if you have more code logging through Common Logging, and you just want to reduce the ammount of logging from Quartz (and not from the rest of the your code), what I recomend is this:

In the log4net config xml (app.config usually) you probably already have something like this:

    <root>
        <level value="ALL" />
        <appender-ref ... />
        ...
    </root>

Leave that as it is. And after that (or anywhere inside the <log4net> config section) just add this:

    <logger name="Quartz">
        <level value="ERROR" />
    </logger>

This <logger> section will configure all the loggers with the namespace "Quartz". So in this example Quartz will be logging with level ERROR while the rest of my app will log with level ALL.

Dolce answered 1/11, 2011 at 21:16 Comment(2)
Actually the question was not how to upper your general logging levels, therefor, this should be marked as the answer, since this is solving the problem.Razz
How to do this programmatically?Iosep
T
18

If any one needs to do this in NLog just add the following as the top most rule in NLog.Config

<!-- Disable Quartz info logging -->
<logger name="Quartz*" minlevel="Trace" maxlevel="Info" final="true" />

Note that this will still let Warn, Error, Fatal go to the other loggers if you don't want that change maxlevel="Info" to maxlevel="Fatal"

Trouble answered 22/10, 2014 at 12:30 Comment(4)
Hey, i've tried your advice, but it disables all athers rules, can you explain more closer how to use it right?Stagnate
You should place it above all other loggers, also ensure that non of you classes are in a namespace or have a classname starting with Quartz as it would disable those to. What it does it tell NLog to ignore all loggers that have a name starting with Quartz.Trouble
may be i'll post the questionStagnate
please see details here #27526176Stagnate
C
7

Quartz.net uses Common.Logging, so something like this in your App.config/Web.config:

<configSections>
    <sectionGroup name="common">
        <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
</configSections>

<common>
    <logging>
        <factoryAdapter type="Common.Logging.Simple.**youradapterhere**, Common.Logging">
            <arg key="level" value="ERROR" />
        </factoryAdapter>
    </logging>
</common>

Be sure to change the youradapterhere to the actual logging adapter you're using, or NoOpLoggerFactoryAdapter if you want to disable logging entirely.


** Edit: ** Based on Ganesh's comment:

<sectionGroup name="common"> 
    <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/> 
</sectionGroup> 
<common>  
    <logging>  
        <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">  
            <arg key="configType" value="INLINE"/>  
            <arg key="configFile" value="filename"/>  
            <arg key="level" value="ERROR" /> <!-- add this line here -->
        </factoryAdapter>  
    </logging> 
</common>

** Edit 2: **

For the benefits of those who don't want to read the comments, the log level was actually set in the log4net root config:

<log4net>
    <root>
        <level value="DEBUG" /> <!-- This is the value that needed changing -->
        <appender-ref ref="Console" />
        <appender-ref ref="RollingFile" />
    </root>
</log4net>
Crigger answered 18/5, 2009 at 11:30 Comment(8)
We are already using the Common.Logging in our ASP .Net application. The entry in the web.config looks as below. Can you help me out as to where do i add the entry you suggested <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/> </sectionGroup> <common> <logging> <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"> <arg key="configType" value="INLINE"/> <arg key="configFile" value="filename"/> </factoryAdapter> </logging> </common>Vagal
I edited my answer with your config and added the relevant line.Crigger
We are also logging info from the component which Quartz .net invokes as a scheduled job. Is it possible to specify multiple values in the key <arg key="level" value="ERROR" /> <!-- add this line here --> Will this be possible <arg key="level" value="ERROR, INFO, WARN" /> Thanks for all your helpVagal
Log4Net docs say the following: "A log request of level L in a logger with (either assigned or inherited, whichever is appropriate) level K, is enabled if L >= K. This rule is at the heart of log4net. It assumes that levels are ordered. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL." The way I interpret that is, if you set loglevel to INFO, you will also get all messages from levels WARN, ERROR and FATAL. So you should replace ERROR with INFO in my example.Crigger
As per your advice i added the specified line to the web.config at the recommended position, but Quartz .Net is still printing the DEBUG log messages. The line I added is <arg key="level" value="INFO" /> Any idea as to why it is not working?Vagal
Do you have any appender-specific configurations that would have a <level value="DEBUG" /> setting in the config file?Crigger
The root tag, configuration is <level value="All"/> and I changed it to <level value="INFO"/> Quartz.Net has stopped the Debug logging but it still logs, minimum of about 5 Info entries per second. Is there a way to control the logging from the jobs.xml file which configures the triggers and schedule for Quartz .Net?Vagal
Not that I know of. Taking a quick peek at some of the sources, it looks like the logging is configured by level, not by action, so I suspect your best bet is just specifying a different log level.Crigger
S
6

In my case for turn off Quartz.net logging I just add this property in my C# code where configuring Scheduler.

LogProvider.IsDisabled = true;

in total view :

public static async void Start()
    {

        LogProvider.IsDisabled = true;
        ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
        IScheduler scheduler = await schedulerFactory.GetScheduler();
        await scheduler.Start();

        IJobDetail job = JobBuilder.Create<SendNotificationJob>().Build();

        ITrigger trigger = TriggerBuilder.Create()

            .WithDailyTimeIntervalSchedule
              (s =>
                 s.WithIntervalInSeconds(1)
                .OnEveryDay()
                .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
              )
            .Build();

        await scheduler.ScheduleJob(job, trigger);
    }

and do not forget to add this using :

using Quartz.Logging;
Shondrashone answered 5/5, 2020 at 9:17 Comment(0)
P
2

For those that do not want Quartz logging at all (i.e. own logging within jobs code is enough) when using NLog (nlog.config):

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="info"
      internalLogFile="path_to_nlog_log_file">

  <!-- the targets to write to -->
  <targets async="true">
    <target name="database" type="Database">
      <commandText>
        <!-- insert into some table -->
      </commandText>
      <!-- parameters here -->
    </target>    

    <target xsi:type="Null" name="blackhole" />
  </targets>

  <!-- rules to map from logger name to target -->
  <rules>
    <!--Skip Microsoft/Quartz logs and so log only own logs-->
    <logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
    <logger name="Quartz*" minlevel="Trace" maxlevel="Info" writeTo="blackhole" final="true" />
    <logger name="*" minlevel="Debug" writeTo="database" />
  </rules>
</nlog>
Politic answered 14/1, 2019 at 8:15 Comment(0)
M
1

If you want to only remove the abundant info & debug logs, I'd add

<logger name="Quartz.*" minlevel="Error" writeTo="default" final="true"/>

Based on this answer. This basically ensures Quartz assembly errors and fatal errors are written, but other logs are not.

Month answered 30/11, 2020 at 8:19 Comment(1)
This looks like what I want but it actually does nothing at all. Full logging is still occurring and I'm not sure why this setting isn't honored.Catafalque

© 2022 - 2024 — McMap. All rights reserved.