我有以下情况,
这一切都没有任何问题。
我现在想要做的是将Quartz Scheduler的默认信息输出记录到另一个单独的NLog日志中,但我无法弄清楚如何管道'从Quartz使用的常见日志框架到NLog。 我的所有日志记录配置都是以编程方式完成的,因此我可以为每个人的作业切换日志记录和关闭状态'在运行时记录。
这是我的NLog配置的缩减版 -
?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">
<targets async="True" xsi:type="AsyncWrapper" queueLimit="20000">
<!--Scheduler Logging Section-->
<target name="sInfo" xsi:type="File"
fileName="${basedir}/logs/Scheduler/SchedulerInfolog.txt"
layout="[${date:format=dd-MM-yyy HH\:mm\:ss}] ${message}"
keepFileOpen="false"
archiveFileName="${basedir}/logs/archive/Scheduler/SchedulerInfoLog{#}.txt"
archiveEvery="Month"
archiveNumbering="Rolling"
maxArchiveFiles="10"
archiveAboveSize="10485760"/>
</targets>
<rules>
</rules>
</nlog>
我在调度程序类中声明了这个,
Private Shared Logger As NLog.Logger = LogManager.GetLogger("Scheduler")
Private xlc As LoggingConfiguration = LogManager.Configuration
Private sInfoRule As New LoggingRule
Private sTraceRule As New LoggingRule
Private sErrorRule As New LoggingRule
Private sfileTarget As New FileTarget
在Quartz Scheduler启动过程中,我调用了一个运行此代码的方法,
If infoEnabled Then
sInfoRule = New LoggingRule("Scheduler", LogLevel.Info, xlc.FindTargetByName("sInfo"))
xlc.LoggingRules.Add(sInfoRule)
sInfoRule.DisableLoggingForLevel(LogLevel.Fatal)
sInfoRule.DisableLoggingForLevel(LogLevel.Error)
sInfoRule.DisableLoggingForLevel(LogLevel.Warn)
End If
LogManager.Configuration = xlc
LogManager.ReconfigExistingLoggers()
我正在配置Quartz Scheduler,
Dim properties = New NameValueCollection()
properties("quartz.scheduler.instanceName") = "SRCTaskScheduler"
properties("quartz.threadPool.type") = "Quartz.Simpl.SimpleThreadPool, Quartz"
properties("quartz.threadPool.threadCount") = "20"
properties("quartz.threadPool.threadPriority")
= "Normal"
properties("quartz.plugin.jobInitializer.type") = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz"
properties("quartz.plugin.jobInitializer.fileNames") = path & "ScheduledTasks.xml"
properties("quartz.plugin.jobInitializer.failOnFileNotFound")
= "true"
properties("quartz.plugin.jobInitializer.scanInterval") = "60"
properties("quartz.plugin.triggerHistory.type") = "Quartz.Plugin.History.LoggingTriggerHistoryPlugin, Quartz"
properties("quartz.plugin.triggerHistory.triggerFiredMessage") = "Trigger
[{1}.{0}] fired job [{6}.{5}] scheduled at: [{2:dd/MM/yyyy HH:mm:ss]}, next scheduled at: [{3:dd/MM/yyyy HH:mm:ss}]"
properties("quartz.plugin.triggerHistory.triggerCompleteMessage") = "Trigger [{1}.{0}] completed firing job [{6}.{5}] with resulting trigger
instruction code: {9}. Next scheduled at: {3:dd/MM/yyyy HH:mm:ss}"
properties("quartz.plugin.triggerHistory.triggerMisfiredMessage") = "Trigger [{1}.{0}] misfired job [{6}.{5}]. Should have fired at: {3:dd/MM/yyyy HH:mm:ss}"
properties("quartz.plugin.jobHistory.type")
= "Quartz.Plugin.History.LoggingJobHistoryPlugin, Quartz"
properties("quartz.plugin.jobHistory.jobToBeFiredMessage") = "Job [{1}.{0}] to be fired by trigger [{4}.{3}] at: [{5:dd/MM/yyyy HH:mm:ss}] with re-fire: {7}"
properties("quartz.plugin.jobHistory.jobSuccessMessage")
= "Job [{1}.{0}] execution complete, next Schedule at: [{6:dd/MM/yyyy HH:mm:ss}] and reports: [{8}] "
properties("quartz.plugin.jobHistory.jobFailedMessage") = "Job [{1}.{0}] execution failed with exception: [{8}]"
properties("quartz.plugin.jobHistory.jobWasVetoedMessage")
= "Job [{1}.{0}] was vetoed. It was to be fired by trigger [{4}.{3}] at: [{2:dd-MM-yyyy HH:mm:ss.SSS}]"
properties("quartz.plugin.ShutdownHook.type") = "Quartz.Plugin.Management.ShutdownHookPlugin, Quartz"
properties("quartz.plugin.ShutdownHook.CleanShutdown")
= "false"
Dim sf As ISchedulerFactory = New StdSchedulerFactory(properties)
_scheduler = sf.GetScheduler()
然后我可以写这个特定的日志文件,
Logger.Trace("[Scheduler configuration has completed.]")
Logger.Info("[Starting Scheduler System.]")
这可能看起来很奇怪,但所有这一切背后的原因是,一旦作业完成,我在该特定作业日志中写下该作业的下一个触发时间,但如果我在调度程序中更改了触发时间,则我没有记录在那个变化的任何地方,它看起来就像那个工作的触发器没有按时触发 - 我最好只是记录Quartz Scheduler输出,因为它在新的时间表中读取,但我想这是一个太大的飞跃。 / p>
我的计划B,如果这是不可能的,就是让一个工作配置为每60秒左右运行一次,并记录当前的调度程序设置,这样可行,但我就像一只带有骨头的狗,并且会想看看是否有可能让A计划工作,我只是没有足够的知识和技能来完成工作。
答案 0 :(得分:0)
这是我在Quartz.Net POC(概念验证)中的NLog。
我注意到的是缺少&lt;规则&gt;在你的配置中。
可能是吗?
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogFile="Nlog.log">
<targets>
<target name="logfileTargetName" xsi:type="File" layout="${longdate}|${level}|${callsite}|${logger}|${threadid}|${windows-identity:domain=false}__${message} ${exception:format=message,stacktrace:separator=*"
fileName="MyNLogLogFile.txt" />
<target name="consoleTargetName" xsi:type="Console" />
<target xsi:type="EventLog"
name="eventTargetName"
layout="${message}"
source="MyCompany.Apps.QuartzPOC.ConsoleAppOne"
eventId="555"
log="Application"
/>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfileTargetName"/>
<logger name="*" minlevel="Info" appendTo="consoleTargetName"/>
<logger name="*" minLevel="Error" writeTo="eventTargetName" />
</rules>
</nlog>