I am looking to integrate ELMAH into an existing ASP.NET application to further support error investigations and could use some help with the connection strings. We use a single web.config file for all or our environments the application is deployed in, and at runtime, the app decides which environment it is in, typically based on URL.
This is what a standard block would like like for us...
<connectionStrings>
<add name="TESTAppDB" connectionString="Data Source=SQL-T-APPNAME.COMPANY.COM;Initial Catalog=APPNAME;User ID=USER;Password=THEPASS" providerName="System.Data.SqlClient"/>
<add name="CERTAppDB" connectionString="Data Source=SQL-C-APPNAME.COMPANY.COM;Initial Catalog=APPNAME;User ID=USER;Password=THEPASS" providerName="System.Data.SqlClient"/>
<add name="PRODAppDB" connectionString="Data Source=SQL-P-APPNAME.COMPANY.COM;Initial Catalog=APPNAME;User ID=USER;Password=THEPASS" providerName="System.Data.SqlClient"/>
</connectionStrings>
With Elmah, it appears that you just need to specify the name of the connection string, but how can I do this dynamically at runtime? For example, if I'm test, then I want this:
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="TESTAppDB"/>
</elmah>
but if I'm in PROD:
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="PRODAppDB"/>
</elmah>
EDIT
The deployment practices for web applications are well out of scope for what I am trying to do. I need a code solution that allows me to change the datasource for the ELMAH Sql Error Log...
I cannot change the way we deploy web apps today. That means, whatever is in TEST, moves to CERT. What is in CERT moves to PROD. The web app must be able to determine which environment it is in and run as such...