本文介绍了Elmah不会在失火时发电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MVC应用,我试图在其中捕获ActionFilter中的所有传入请求。这是日志记录代码。我正在尝试登录并忘记模型。
I have a MVC app where I am trying to capture all the incoming requests in a ActionFilter. Here is the logging code. I am trying to log in a fire and forget model.
我的问题是,如果我通过取出Task来同步执行此代码。RunElmah确实会发送电子邮件。但是对于下面显示的代码,我可以看到该错误已记录到elmah.axd中的InMemory记录器中,但没有电子邮件。
My issue is if I execute this code synchronously by taking out the Task.Run Elmah does send out an email. But for the code shown below I can see the error getting logged to the InMemory logger in elmah.axd but no emails.
public void Log(HttpContextBase context)
{
Task.Run(() =>
{
try
{
throw new NotImplementedException(); //simulating an error condition
using (var s = _documentStore.OpenSession())
{
s.Store(GetDataToLog(context));
s.SaveChanges();
}
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
}
});
}
推荐答案
从Atif Aziz得到了这个答案(ELMAH首席贡献者)在ELMAH谷歌论坛上:
Got this answer from Atif Aziz (ELMAH Lead contributor) on the ELMAH google group:
这篇关于Elmah不会在失火时发电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!