使用 IJobListener 获取作业异常 (Quartz.NET)

发布于 2024-09-30 03:14:42 字数 407 浏览 4 评论 0原文

我正在 Quartz.NET 中使用 IJobListener 来审核所有作业成功/失败。当作业失败时,我希望将异常放入 IJobListener 中,以便也可以存储异常以供以后分析。

目前我的作业侦听器是这样的:

public virtual void JobWasExecuted(JobExecutionContext context, JobExecutionException x)
        {

}

但是,即使作业的 Execute 方法中的所有事务都包含在带有 catch(Exception x) 的 try 中,然后我抛出该 try,JobExecutionException 的“x”也永远不会填充。

是否有一种特殊的方法来实际获取作业侦听器的异常?

谢谢

I'm using an IJobListener in Quartz.NET to audit all job successes/failures. When a job fails, I want the exception to be taken into the IJobListener so the exception can be stored too for later analysis.

Currently my job listener is like this:

public virtual void JobWasExecuted(JobExecutionContext context, JobExecutionException x)
        {

}

But even though all transactions in the Execute method for the job are encased in a try with a catch(Exception x), which I then throw, the 'x' for JobExecutionException is never populated.

Is there a special way of actually getting the exception to the job listener?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚雾 2024-10-07 03:14:42

你只是抛出异常吗?您是否尝试过将其包装在 JobWasExecuted 期望的正确类型中?

public virtual void Execute(JobExecutionContext context)
{
    try 
    {
      //divide by zero... or something else that causes an exception
    }
    catch (Exception e)
    {
      JobExecutionException je = new JobExecutionException(e);
      je.RefireImmediately = true;  //do something with the exception
      throw je;  //throw JobExecutionException
    }
}

Do you just throw the Exception? Have you tried wrapping it in the right Type that JobWasExecuted is expecting?

public virtual void Execute(JobExecutionContext context)
{
    try 
    {
      //divide by zero... or something else that causes an exception
    }
    catch (Exception e)
    {
      JobExecutionException je = new JobExecutionException(e);
      je.RefireImmediately = true;  //do something with the exception
      throw je;  //throw JobExecutionException
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文