我使用Quartz.NET在我们的应用程序安排一些自定义的任务。一切正常,除了它记录在一秒约二十调试条目。

我不知道如何关闭调试日志记录。任何帮助将非常感激,因为我一直在尝试,没有运气净查找。

调试条目看起来像下面的

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
有帮助吗?

解决方案

Quartz.net使用Common.Logging,所以像这样在你的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>

一定要改变的 youradapterhere 的,如果你想禁用完全记录您在使用,或NoOpLoggerFactoryAdapter实际日志适配器。


**编辑:** 基于Ganesh的评论:

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

**编辑2:**

对于不想阅读评论谁的人的利益,日志级别实际上是在log4net的根配置设置:

<log4net>
    <root>
        <level value="DEBUG" /> <!-- This is the value that needed changing -->
        <appender-ref ref="Console" />
        <appender-ref ref="RollingFile" />
    </root>
</log4net>

其他提示

如果你

Rytmis的回答是伟大的想降低您的所有记录其经过的通用日志的基础设施。

但如果你有更多的代码通过通用日志记录,而你只是想减少日志记录的ammount的石英(并不会从你的代码的其余部分),有什么我建议是这样的:

在log4net的配置XML(app.config通常情况下),你可能已经有这样的事情:

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

保留其原样。而在此之后(或<log4net>配置部分内的任何地方)只需要添加这样的:

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

<logger>部分将配置所有与命名空间“石英”的记录器。因此,在这个例子中石英将与水平ERROR被记录,而我的应用程序的其余部分将记录与水平ALL

如果任一项需要为此在NLOG只是添加以下作为NLog.Config顶端moste规则

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

请注意,这仍然会让警告,错误,致命转到其他记录器,如果你不希望改变maxlevel="Info"maxlevel="Fatal"

对于那些不希望石英在所有(即自己的日志记录内的作业代码就足够了)记录使用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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top