Specify API key and log ID through appSettings
When integrating to elmah.io from ASP.NET, MVC, Web API and similar, we use the open source project ELMAH to log uncaught exceptions. ELMAH requires configuration in
web.config, which in the case of elmah.io could look something like this:
<elmah> <errorLog type="Elmah.Io.ErrorLog, Elmah.Io" apiKey="API_KEY" logId="LOG_ID" /> </elmah>
You'd normally use web.config Transformations to specify different API keys and log IDs for different environments (see Use multiple logs for different environments). When hosting on Microsoft Azure (and other cloud-based offerings), a better approach is to specify the configuration in the
appSettings element and overwrite values through the web app settings in the Portal.
The elmah.io clients built for ASP.NET based web frameworks support this scenario through additional attributes on the
<appSettings> <add key="apiKeyRef" value="API_KEY" /> <add key="logIdRef" value="LOG_ID" /> </appSettings> <!-- ... --> <elmah> <errorLog type="Elmah.Io.ErrorLog, Elmah.Io" apiKeyKey="apiKeyRef" logIdKey="logIdRef" /> </elmah>
Unlike the first example, the term Key has been appended to both the
logId attributes. The values of those attributes need to match a key specified in
appSettings (in this example apiKeyRef and logIdRef). How you choose to name these keys is entirely up to you, as long as the names match.
This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening, and help you fix errors fast.