我写了下面的自定义作业监听器。(不是一个非常健壮的)。
有没有办法通过 .config 连接这个监听器(在更具体的元素中)
“GranadaCoder.Apps.QuartzPOC.BAL.Listeners.MyFirstJobListener,GranadaCoder.Apps.QuartzPOC”
后续问题是..您可以添加多个自定义 JobListener 吗?
我看到了对象模型 (C#) 代码。我只是没有通过.config 看到它。
IJobListener jobListener001 = new MyFirstJobListener ();
sched.ListenerManager.AddJobListener(jobListener001, GroupMatcher<JobKey>.AnyGroup());
谢谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Logging;
using Quartz;
/* Assembly Name = "GranadaCoder.Apps.QuartzPOC" */
namespace GranadaCoder.Apps.QuartzPOC.BAL.Listeners
{
public class MyFirstJobListener : IJobListener
{
public void JobExecutionVetoed(IJobExecutionContext context)
{
string msg = string.Format(" MyFirstJobListener : JobExecutionVetoed fired. Key = '{0}'.", context.JobDetail.Key);
Console.WriteLine(msg);
ILog log = LogManager.GetLogger(typeof(MyFirstJobListener));
log.Info(msg);
}
public void JobToBeExecuted(IJobExecutionContext context)
{
string msg = string.Format(" MyFirstJobListener : JobToBeExecuted fired. Key = '{0}'.", context.JobDetail.Key);
Console.WriteLine(msg);
ILog log = LogManager.GetLogger(typeof(MyFirstJobListener));
log.Info(msg);
}
public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
{
string msg = string.Format(" MyFirstJobListener : JobWasExecuted fired. Key = '{0}'.", context.JobDetail.Key);
Console.WriteLine(msg);
ILog log = LogManager.GetLogger(typeof(MyFirstJobListener));
log.Info(msg);
if (null != jobException)
{
StringBuilder sb = new StringBuilder();
Exception exc = jobException;
while (null != exc)
{
sb.Append(exc.Message + " --- ");
exc = exc.InnerException;
}
string sbMsg = sb.ToString();
msg = string.Format(" MyFirstJobListener : JobWasExecuted fired. jobException.Message = '{0}'.", sbMsg);
Console.WriteLine(msg);
log.Info(msg);
}
}
public string Name
{
get
{
return " MyFirstJobListener : MyFirstJobListener.Name Property";
}
}
}
}