This post is compatible with Windows Azure SDK v1.3 and v1.4

When using Windows Azure, you may come across the need to trace information and not worry about connecting all the Diagnostics information.  I saw this question on StackOverflow which pretty much asks the same point – how do I get ASP.NET tracing info into the Azure Compute Emulator? Here’s the answer.

By default this happens for WorkerRoles and WebRoles when in the context of the RoleEntryPoint. In a Web Role, your trace from WebRole.cs goes into the Compute Emulator, but does not when you are in default.aspx.cs or any other code executing inside the application. The reason for this is that the RoleEntryPoint runs in a different application pool context to the web application itself, and it has different TraceListeners added to the Trace.Listeners collection.

If we want to trace to the Compute Emulator (what used to be called DevFabric) we can very simply add a TraceListener to the collection and get the output in the Compute Emulator UI.

Note: You shouldn’t do this in production – and so you may wish to configure the adding of the TraceListener programmatically, or remove the code before you deploy.

I added a new TraceListener to the config, but left the DiagnosticMonitorTraceListener so that other diagnostic activities are not disrupted. The web.config entry is:


    
      
        
          
        
        
          
        
      
    
  

The output looks like:

The output in Compute Emulator

The output in Compute Emulator

You can download my basic project: AspnetComputeTracing

About these ads