通过log4net的Quartz调度程序日志来自错误的日志文件

时间:2018-05-10 13:49:54

标签: log4net .net-4.5 quartz-scheduler quartz.net log4net-configuration

我有两个项目:一个(MyApp.QuartzImplementation),其中所有初始化和石英工作相关的工作完成,而另一个项目(MyApp.XYZApi)做其他工作。

我为每个项目都有单独的log4net日志文件。我遇到的问题是调度程序相关的日志来自我的主项目(MyApp.XYZApi)日志,虽然我已经从另一个项目(MyApp.QuartzImplementation)初始化了调度程序。

主项目日志文件中的示例日志是

2018-05-10 17:01:06.034 INFO    TANG_DM N1  16              StdSchedulerFactory.Log     Quartz scheduler 'DBScheduler' initialized
2018-05-10 17:01:06.050 INFO    TANG_DM N1  16              StdSchedulerFactory.Log     Quartz scheduler version: 3.0.4.0
2018-05-10 17:01:06.087 DEBUG   TANG_DM N1  16              SimpleSemaphore.Log     Lock 'TRIGGER_ACCESS' is desired by: 75af30b2-9658-4b61-b2ca-6bf3d74f6486
2018-05-10 17:01:06.087 DEBUG   TANG_DM N1  16              SimpleSemaphore.Log     Lock 'TRIGGER_ACCESS' is being obtained: 75af30b2-9658-4b61-b2ca-6bf3d74f6486
2018-05-10 17:01:06.103 DEBUG   TANG_DM N1  16              SimpleSemaphore.Log     Lock 'TRIGGER_ACCESS' given to: 75af30b2-9658-4b61-b2ca-6bf3d74f6486
2018-05-10 17:01:06.119 DEBUG   TANG_DM N1  15              DeviceDataManager.StartOtpExpiryJob     Sleeping For 1 Hours
2018-05-10 17:01:06.188 DEBUG   TANG_DM N1  16              SQL.Log     Prepared SQL: UPDATE QRTZ_TRIGGERS SET TRIGGER_STATE = @newState WHERE SCHED_NAME = 'DBScheduler' AND (TRIGGER_STATE = @oldState1 OR TRIGGER_STATE = @oldState2)
2018-05-10 17:01:06.266 DEBUG   TANG_DM N1  16              SQL.Log     Prepared SQL: UPDATE QRTZ_TRIGGERS SET TRIGGER_STATE = @newState WHERE SCHED_NAME = 'DBScheduler' AND (TRIGGER_STATE = @oldState1 OR TRIGGER_STATE = @oldState2)
2018-05-10 17:01:06.272 INFO    TANG_DM N1  16              JobStoreTX.Log      Freed 0 triggers from 'acquired' / 'blocked' state.
2018

我的log4net配置如下所示

<?xml version="1.0" encoding="utf-8" ?>
<log4net>  
  <appender name="MyAppXYZApi" type="log4net.Appender.RollingFileAppender" >
    <file value="..\\Logs\\XYZ_DM_N1" />
    <encoding value="utf-8" />
    <appendToFile value="true" />
    <datePattern value="_yyyyMMdd'.log'" />
    <staticLogFileName value="false" />
    <rollingStyle value="Composite"/>
    <maxSizeRollBackups value="-1"/>
    <maximumFileSize value="10MB"/>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <filter type="log4net.Filter.LevelRangeFilter">
      <acceptOnMatch value="true" />
      <levelMin value="DEBUG" />
      <levelMax value="FATAL" />
    </filter>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%d{yyyy-MM-dd HH:mm:ss.fff}&#9;%p&#9;XYZ_DM&#9;N1&#9;%t&#9;%property{ExternalIP}&#9;%property{ContextId}&#9;%property{ContextValue}&#9;%c{1}.%M&#9;%property{SessionId}&#9;%m%n" />
    </layout>
  </appender>
  <appender name="QuartzScheduling" type="log4net.Appender.RollingFileAppender" >
    <file value="..\\Logs\\XYZ_QuartzScheduling_N1" />
    <encoding value="utf-8" />
    <appendToFile value="true" />
    <datePattern value="_yyyyMMdd'.log'" />
    <staticLogFileName value="false" />
    <rollingStyle value="Composite"/>
    <maxSizeRollBackups value="-1"/>
    <maximumFileSize value="10MB"/>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <filter type="log4net.Filter.LevelRangeFilter">
      <acceptOnMatch value="true" />
      <levelMin value="DEBUG" />
      <levelMax value="FATAL" />
    </filter>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%d{yyyy-MM-dd HH:mm:ss.fff}&#9;%p&#9;XYZ_QuartzScheduling&#9;N1&#9;%t&#9;%property{ExternalIP}&#9;%property{ContextId}&#9;%property{ContextValue}&#9;%c{1}.%M&#9;%property{SessionId}&#9;%m%n" />
    </layout>
  </appender>
  <root>
    <level value="ALL" />
    <appender-ref ref="MyAppXYZApi" />
  </root>
  <logger additivity="false" name="MyApp.XYZApi">
    <level value="ALL"/>
    <appender-ref ref="MyAppXYZApi" />
  </logger> 
  <logger additivity="false" name="MyApp.QuartzImplementation">
    <level value="ALL"/>
    <appender-ref ref="QuartzScheduling" />
  </logger>
</log4net>

如果我可以将石英的调度程序日志写入特定日志文件,请告诉我

当我按照以下建议添加%logger时,日志中的石英命名空间

Quartz.Util.DBConnectionManager 
Quartz.Impl.StdSchedulerFactory 
Quartz.Simpl.TaskSchedulingThreadPool 
Quartz.Core.SchedulerSignalerImpl 
Quartz.Impl.AdoJobStore.StdAdoDelegate 
Quartz.Core.QuartzScheduler 
Quartz.Impl.AdoJobStore.SimpleSemaphore 
Quartz.Impl.AdoJobStore.MisfireHandler 
Quartz.Core.QuartzSchedulerThread 
Quartz.SQL 
Quartz.Impl.AdoJobStore.JobStoreTX 

我可以将所有这些内容放在一个单独的appender中吗

1 个答案:

答案 0 :(得分:2)

看起来你需要改变

<logger additivity="false" name="MyApp.QuartzImplementation">

<logger additivity="false" name="Quartz">