Quartz 调度程序通过 log4net 记录错误的日志文件

Quartz scheduler logs via log4net coming in wrong log file

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

我为每个项目准备了单独的 log4net 日志文件。我遇到的问题是尽管我已经从另一个项目 (MyApp.QuartzImplementation).

初始化了调度程序,但与调度程序相关的日志出现在我的主项目 (MyApp.XYZApi) 日志中

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

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>

请告诉我是否可以将 quartz 的调度程序日志写入特定日志文件

当我按照建议添加 %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 中吗

看来你需要改变

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

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