0

I'm using Elmah and what I would like to happen is that when one of our multiple developers is running their project locally, they only receive any error emails generated from that local instance, if the error is generated on the live server, email a different (group) email. Right now we are just using the (horrible) method of each person having their own web.config that shouldn't (but sometimes does) get committed to our Repo, and then changing the email string when deploying to live.

We are all using VS 2010 and Cassini, but the developers could be working from their work computer or their home computer where they connect through VPN, but their login name on their home computer doesn't reflect their work computer username.

Basically all I have so far is this ELMAH email setting:

<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ElmahDb" />
<errorMail from="no-reply@mydomain.com" to="myemail@mydomain.com" subject="Project Error" smtpPort="0" async="false" />

And an empty method in Application_Start:

protected void Application_Start()
    {
        Config.SetErrorEmailReceiver();
    }

public static void SetErrorEmailReceiver()
    {
        //some logic
    }
SventoryMang
  • 10,275
  • 15
  • 70
  • 113
  • Do you actually want developers sent emails when they are developing (that seems like it would be really annoying), *or* do you just want to turn on emailing when the code is running in production? If the latter, then you should be using a web.config transformation. – aquinas Jan 29 '13 at 18:34
  • The former, we run emails when developing and on production. – SventoryMang Jan 29 '13 at 18:38

1 Answers1

2

The best approach is probably to use an external config file. So, you would change your web.config to say:

<errorMail configSource="elmah-errorMail.config" /> 

And then each developer would have their own copy of that file which would contain:

<errorMail from="no-reply@mydomain.com" to="myemail@mydomain.com" subject="Project Error" smtpPort="0" async="false" />

And then of course you also have the production values on your production web server.

I still don't understand why you want emails sent out to the developer though. Isn't a yelllow screen of death enough of an alert :)

aquinas
  • 23,318
  • 5
  • 58
  • 81
  • Sometimes we get distracted or need to attend to some 'urgent' matter that may or may not in that page being closed, so it's nice that when you can resume 'normal development' just check the email to see where you were at. This seems decent but there could be a repo issue here. Let's say I just formatted my home computer and do a fresh check out of the code. Either I get one that could have the wrong value (if we commit this file), or I get no file and something wouldn't work right. I am trying to keep everything as automatic as possible. Is there anyway to get the VPN user locally? – SventoryMang Jan 29 '13 at 18:58
  • 1
    You would *never* commit this file. So, yes, every developer when they reformat their hard drive would have to spend 10 seconds adding this file to their local machine. :) I would even include a sample version of the file named something like: elmah-errorMail.config.sample. Then you simply copy and paste that file and fill in your email address. – aquinas Jan 29 '13 at 19:03