ELMAH:没有例外的HttpContext? [英] elmah: exceptions without HttpContext?

查看:147
本文介绍了ELMAH:没有例外的HttpContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在产卵一个的Application_Start线程,并想记录异常。没有上下文/的HttpContext / HttpContext.Current ,所以我怎么可能会得到它登录?

I spawn a thread on Application_Start and would like to log exceptions. There is no Context/HttpContext/HttpContext.Current, so how might I get it to log?

目前,它并不在我的线程捕捉任何异常,如果我写 ErrorSignal.FromCurrentContext()提高(前); 我得到关于环境的错误不能为null。

At the moment, it does not catch any exception in my threads and if I write ErrorSignal.FromCurrentContext().Raise(ex); I get an error about context cannot be null.

也许我可以创建一个虚拟的HttpContext,但不知何故,我不认为这会工作得很好。

Maybe I can create a dummy HttpContext but somehow I don't think that will work well.

-edit - 我试图 ErrorSignal.Get(新的HttpApplication())提高(前); ,它似乎没有不拿起例外。

-edit- I tried ErrorSignal.Get(new HttpApplication()).Raise(ex); and it doesn't seem to pick up that exception.

推荐答案

请确保您在web.config中设置您的应用程序的名称

Make sure you set your application name in web.config

<errorLog type="Elmah.SqlErrorLog, Elmah" 
          connectionStringName="nibWeb" 
          applicationName="Nib.Services" />

然后

ErrorLog.GetDefault(null).Log(new Error(error));

将工作

这篇关于ELMAH:没有例外的HttpContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆