Search code examples
asp.net-mvcazureelmah

Elmah in an Azure Web Site


I'm trying to migrate a bunch of ASP.Net MVC web sites to Azure. In the process I've noticed that Elmah does not function on any of those web sites. I created the simplest case possible to test with and found that it doesn't work either.

On Azure I created a "standard tier" web site, I did no further configuration to it.

In Visual studio I created a new ASP.NET MVC web site. I added the Nuget "Elmah" package. I changed one line in the web.config to:

<security allowRemoteAccess="true" />

This change was done to allow me to view the elmah page. (I know insecure, but just trying to prove a point)

I also changed the controller so that clicking the about menu generates an exception. Otherwise this is a generic MVC web site. Locally everything works great and I can generate the exception and see it show up on the Elmah.axd page, but once I deploy the site to Azure no data ever appears on the Elmah page.

I have left the sample online for demonstration purposes:

  1. Start at: http://testelmah.azurewebsites.net/elmah.axd

  2. Next go to: http://testelmah.azurewebsites.net and click about. You should see an error message indicating an exception occured.

  3. Go back to: http://testelmah.azurewebsites.net/elmah.axd

  4. Be puzzled that Elmah isn't working

I've spent hours googling for a solution and it seems that Elmah just works for everyone else in Azure. What am I missing?


Solution

  • I think that your problem is, that you're running with custom errors enabled and/or using the HandleErrorAttribute. You probably get a yellow screen of death when running on localhost and the "nice" error page when running on Azure. Your custom errors may be configured in web.release.config.

    You should consider using the Elmah.MVC NuGet package, because this helps you log errors in ELMAH when running with custom errors and the HandleError attribute from ASP.NET MVC.