【问题标题】:Log execution of Quartz.Net jobs in a custom format以自定义格式记录 Quartz.Net 作业的执行
【发布时间】:2014-11-07 08:37:12
【问题描述】:

我正在使用Quartz.Net 作为调度系统的 Windows 服务。内置日志系统使用 Common.Logging 框架,但只记录“初始化期间的一些信息,然后只记录有关作业执行时严重问题的消息”(参见 @ 987654322@ - 底部)。

为了记录我的作业的实际执行历史记录,我通过在服务的 quartz.config 文件中添加此行成功配置了 LoggingJobHistoryPlugin

quartz.plugin.triggHistory.type = Quartz.Plugin.History.LoggingJobHistoryPlugin

此时,执行记录工作正常(在所有附加程序中 - SQL 数据库、文件等)。您可以在此处查看摘录:

426 2014-11-07 10:30:05.997 ServerScheduler_Worker-7    INFO    Quartz.Plugin.History.LoggingJobHistoryPlugin.JobWasExecuted(c:\Work\OpenSource\quartznet\src\Quartz\Plugin\History\LoggingJobHistoryPlugin.cs:432) Job Admin.Auto Sync execution complete at 08:30:05 11/07/2014 and reports: 
425 2014-11-07 10:30:00.070 ServerScheduler_Worker-7    INFO    Quartz.Plugin.History.LoggingJobHistoryPlugin.JobToBeExecuted(c:\Work\OpenSource\quartznet\src\Quartz\Plugin\History\LoggingJobHistoryPlugin.cs:383)    Job Admin.Auto Sync fired (by trigger admin.Admin) at: 08:30:00 11/07/2014

我想要实现的是更改默认的日志记录格式,如here 所述。我尝试的是在quartz.config 文件中设置这些行:

quartz.plugin.triggHistory.jobToBeFiredMessage = *** Job {1}.{0} fired (by trigger {4}.{3}) at: {2, date, HH:mm:ss MM/dd/yyyy}
quartz.plugin.triggHistory.jobSuccessMessage = *** Job {1}.{0} execution complete at {2, date, HH:mm:ss MM/dd/yyyy} and reports: {8}
quartz.plugin.triggHistory.jobFailedMessage = *** Job {1}.{0} execution failed at {2, date, HH:mm:ss MM/dd/yyyy} and reports: {8}

但添加这些行后,我在日志中收到以下错误:

384 2014-11-07 10:24:00.037 ServerScheduler_Worker-3    ERROR   Quartz.Core.QuartzScheduler.NotifySchedulerListenersError(c:\Work\OpenSource\quartznet\src\Quartz\Core\QuartzScheduler.cs:1877) Unable to notify JobListener(s) of Job to be executed: (Job will NOT be executed!). trigger= Test.Tr5 job= Test.1 minute    
383 2014-11-07 10:23:00.027 ServerScheduler_Worker-2    ERROR   Quartz.Core.QuartzScheduler.NotifySchedulerListenersError(c:\Work\OpenSource\quartznet\src\Quartz\Core\QuartzScheduler.cs:1877) Unable to notify JobListener(s) of Job to be executed: (Job will NOT be executed!). trigger= Test.Tr5 job= Test.1 minute    
382 2014-11-07 10:22:00.143 ServerScheduler_Worker-1    ERROR   Quartz.Core.QuartzScheduler.NotifySchedulerListenersError(c:\Work\OpenSource\quartznet\src\Quartz\Core\QuartzScheduler.cs:1877) Unable to notify JobListener(s) of Job to be executed: (Job will NOT be executed!). trigger= Test.Tr5 job= Test.1 minute    

任何想法我怎样才能做到这一点?

【问题讨论】:

    标签: c# asp.net service quartz.net


    【解决方案1】:

    很遗憾,API 文档有误,我现在在 more up-to-date 2.0 documentation 中进行了更正。日期的正确格式是标准的 .NET 字符串格式:

    quartz.plugin.triggHistory.jobToBeFiredMessage = *** Job {1}.{0} fired (by trigger {4}.{3}) at: {2:HH:mm:ss MM/dd/yyyy}
    quartz.plugin.triggHistory.jobSuccessMessage = *** Job {1}.{0} execution complete at {2:HH:mm:ss MM/dd/yyyy} and reports: {8}
    quartz.plugin.triggHistory.jobFailedMessage = *** Job {1}.{0} execution failed at {2:HH:mm:ss MM/dd/yyyy} and reports: {8}
    

    【讨论】:

    • 对此我还有一个问题:登录JobFailedMessage 时如何获得实际的错误消息?我只能使用{8} 获得details,但这根本没有帮助。例如,对于(401) Unauthorized 异常,我只能记录Job threw an unhandled exception.,而不是实际的错误消息。
    • 通常作为作业应该抛出一个 JobExecutionException,我会尝试用 try-catch 包装你的作业主执行,并将原始异常的消息作为 JobExecutionException 抛出。否则对于非 JobExecutionExceptions Quartz 将包装它们并且原始错误仅作为 InnerException 可用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    相关资源
    最近更新 更多