Why global tracing doesnt work in Azure web apps
22 Jul 2015Having spent a couple of hours troubleshooting this before finally finding a solution, I thought I’d provide a brief write up in the hope it might save someone else the pain. Of course, tracing does work in Azure, but there’s a common scenario gotcha that doesn’t seem to be covered in any of the major documentation.
Scenario
- You want to make use of Azure’s Application Logging, whether it be to the file system, table storage, or blob storage.
- You want to log to this diagnostic destination with Trace.TraceError(“your trace message”) and equivalent methods.
- You’re working on a web app, so want to globally capture exceptions in global.asax.cs and make your tracing call from here.
The problem
You set up exception interception and capturing in Application_Error() in global.asax.cs and fire off a trace call. You try it out in your local development environment and it works as expected. However, upon deploying the application to Azure, nothing is logged when an exception occurs.
What’s going on?
You probably have **
Fixing this is as simple as registering a custom exception filter and making your tracing calls from there instead. Details for achieving that can be found in this Stack Overflow answer.