使用什么来记录 Quartz 计划作业中的错误?

发布于 2024-11-14 07:21:26 字数 862 浏览 4 评论 0原文

我有一个 asp.net mvc 3 应用程序。在这个应用程序中,我有一个提醒系统,它使用石英从数据库中抓取消息并将其发送出去。

我想知道如果发生某些情况(比如数据库超时 - 我想知道这一点),记录日志的最佳方式是什么。

我在我的 mvc 应用程序中使用 ELMAH 进行日志记录,效果很好。然而,由于quartz.net是它自己的线程,没有httpcontext,我不能使用ELMAH(或者至少我不认为我可以)。我尝试通过首先查询我的主页,然后通过调度程序代码并将其用作上下文来创建 httpcontext,但这不起作用。

System.ArgumentNullException was unhandled by user code
  Message=Value cannot be null.
Parameter name: application
  Source=Elmah
  ParamName=application
  StackTrace:
       at Elmah.ErrorSignal.Get(HttpApplication application)
       at Elmah.ErrorSignal.FromContext(HttpContext context)
       at Job.Execute(JobExecutionContext context) in Job.cs:line 19
       at Quartz.Core.JobRunShell.Run()
  InnerException: 

ErrorSignal.FromCurrentContext().Raise(new System.Exception());

所以我正在寻找如何让 ELMAH 在这种情况下工作或类似的东西(发送电子邮件、堆栈跟踪和 ELMAH 拥有的一切)。

I have an asp.net mvc 3 application. In this application I have a reminder system that uses quartz to grab messages from the database and send them out.

I am wondering what is the best way to log if something happens(say the database times out - I want to know about this).

I use in my mvc application ELMAH for my logging and it works great. However since quartz.net is it's own thread with out the httpcontext I can't use ELMAH(or at least I don't think I can). I tried to make an httpcontext by first querying my home page then through the scheduler code and using that as the context but that did not work.

System.ArgumentNullException was unhandled by user code
  Message=Value cannot be null.
Parameter name: application
  Source=Elmah
  ParamName=application
  StackTrace:
       at Elmah.ErrorSignal.Get(HttpApplication application)
       at Elmah.ErrorSignal.FromContext(HttpContext context)
       at Job.Execute(JobExecutionContext context) in Job.cs:line 19
       at Quartz.Core.JobRunShell.Run()
  InnerException: 

ErrorSignal.FromCurrentContext().Raise(new System.Exception());

So I am looking for either how to get ELMAH working in this scenario or something comparable to it(something that sends emails, stack trace and everything nice ELMAH has).

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

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

发布评论

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

评论(1

¢蛋碎的人ぎ生 2024-11-21 07:21:26

您可以尝试NLog。实施起来非常简单且有效。
您可以发送电子邮件,跟踪几乎所有内容。
我通常倾向于将所有内容保存在单独的配置文件(NLog.Config)中,

<?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" >
    <targets>
        <target name="DebugHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${identity} ${aspnet-request}   ${message}  ${exception}" />
        <target name="ErrorHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
        <target name="FatalHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
        <target name="GenericHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
    </targets>
    <rules>
        <logger name="*" level="Debug" appendTo="DebugHandler" />
        <logger name="*" level="Error" appendTo="ErrorHandler" />
        <logger name="*" level="Fatal" appendTo="FatalHandler" />
        <logger name="*" levels="Info,Warn" appendTo="GenericHandler" />
    </rules>
</nlog>

正如您所看到的,您可以激活或停用不同的级别。

我已经在quartz.net 工作以及调试/跟踪系统中使用了它,并且它完成了它的工作。

唯一的限制是您没有 ELMAH 接口,有时这可能是一个巨大的限制。

You can try NLog. It's very simple to implement and effective.
You can send email, trace pretty much everything.
I normally tend to keep everything in a separate config file (NLog.Config)

<?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" >
    <targets>
        <target name="DebugHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${identity} ${aspnet-request}   ${message}  ${exception}" />
        <target name="ErrorHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
        <target name="FatalHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
        <target name="GenericHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
    </targets>
    <rules>
        <logger name="*" level="Debug" appendTo="DebugHandler" />
        <logger name="*" level="Error" appendTo="ErrorHandler" />
        <logger name="*" level="Fatal" appendTo="FatalHandler" />
        <logger name="*" levels="Info,Warn" appendTo="GenericHandler" />
    </rules>
</nlog>

As you can see you can activate or deactivate the different levels.

I've used it on in my quartz.net jobs as well as a debugging/tracing system and it does its job.

The only limit is you do not have an ELMAH interface, which can be a huge limit sometimes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文