开发者

How to enable and disable ELMAH in web.config and in code behind?

I am using ELMAH for error reporti开发者_高级运维ng in my ASP.NET projects. Everything is working great, except when I debug a project I don't want to send an email report to the allowed users. How can I accomplish this feat?


Assuming you have different web.config files for your development and production environments, just disable Elmah in your development web.config. You'll want to comment out (or remove) the Elmah.ErrorLogModule element in the httpModules section.


Maybe you can use ErrorFiltering to turn off the email logging in the Global.asax. Something like:

void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
{

#if DEBUG
    e.Dismiss();
#endif

}


Another way is to use the ErrorMail_Mailing method. When ELMAH sends the email, it runs this first (when present in global.asax.cs)

public void ErrorMail_Mailing(object sender, ErrorMailEventArgs e)
{
#if DEBUG
    e.Mail.To.Clear();
    e.Mail.To.Add("MyAddress@myDomain.com");
    e.Mail.Subject = "Error in Development";
#endif
}

The example above can be via the the transformations in web.Debug.config & web.Release.config. But there is a lot more you can do in this method. See http://scottonwriting.net/sowblog/archive/2011/01/06/customizing-elmah-s-error-emails.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜