8

I am using ELMAH for error reporting 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?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Sean N
  • 81
  • 1
  • 3
  • can you please tell us HOW you are sending emails when an error occurs? I'm assuming you're using ELMAH to send emails when an error occurs .. so can you please show us your web.config settings for ELMAH? – Pure.Krome Apr 20 '11 at 01:17

3 Answers3

8

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.

Jim Lamb
  • 25,355
  • 6
  • 42
  • 48
  • 2
    I'm not aware of a way to disable ELMAH from code-behind. You can, however, use configuration-specific web.config files to turn it off (or just use a different type of logging) in your development environment. See ScottGu's post here: http://weblogs.asp.net/scottgu/archive/2007/09/21/tip-trick-automating-dev-qa-staging-and-production-web-config-settings-with-vs-2005.aspx – Jim Lamb Oct 10 '09 at 04:40
  • It doen't work to comment ErrorLogModule. Comment errorLog from elmah section ! http://stackoverflow.com/a/25394016/2152973 – François Breton Jan 21 '16 at 19:30
6

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

}
Eric King
  • 11,594
  • 5
  • 43
  • 53
0

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

Jupiter
  • 73
  • 6