使用什么来记录 Quartz 计划作业中的错误?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试NLog。实施起来非常简单且有效。
您可以发送电子邮件,跟踪几乎所有内容。
我通常倾向于将所有内容保存在单独的配置文件(NLog.Config)中,
正如您所看到的,您可以激活或停用不同的级别。
我已经在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)
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.