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:
You can download my basic project: AspnetComputeTracing

Andy – thanks for the post – worked like a charm.
Side question: While this runs just fine, Visual Studio complains about this new config line with two warnings while looking at web.config:
1. The “Runtime.DevelopmentFabricTraceListener” part of “Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.DevelopmentFabricTraceListener” is in red and the hover message is “Cannot resolve symbol ”DevelopmentFabricTraceListener””
2. All of “Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ has red squiggly underlining (which VS Options says is for “Other Error”) and the message is “Invalid module qualification: Failed to resolve assembly Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime”
Do you see these warnings when viewing within Visual Studio 2010?
Hi Bill,
I”m glad the technique worked for you.
I don”t see that warning message. I wonder if maybe it”s something to do with the reference to the assembly. Did you add the TraceListener to your existing project or try opening up the example I posted? Just for sanity it might be worth opening up the example and seeing if that”s got the same issue.
Out of interest, the way I resolved the assembly name was to put a breakpoint in WebRole.cs OnStart, open up a QuickWatch dialog when it role hits the breakpoint and look for the TraceListener:
System.Diagnostics.Trace.Listeners[1].GetType().AssemblyQualifiedName
Trace.Listeners[0] is a DefaultTraceListener, and Trace.Listeners[1] is the DevelopmentFabricTraceListener.
Andy
Thanks. Works like a charm.
Thanks Andy that works fine how I could not get the programmatic set up to work. Do you have sample code for that ? When I add the listener programmatically it seems to have no effect.
hi Clement,
I do have a sample, I”ll email you it.
Best wishes,
Andy
The web config entry shows up as blank on my end, can you re-post this text? Thank you.
Ok Haddicus – there is a problem with the JS auto formatter here… I”ll try to fix it!
This is the xml if I can”t managed to fix it!:
Note that I am working on a different solution at the below seems to have difficulty in V1.5
Hello. Could you fix the post, regarding the web.config entry, which is not seen in the browser, and provide a new link to the basic project? I am interested in “configure the adding of the TraceListener programmatically”, so that I have the same code for both situations: local testing, and deploy environment. Or, you could write the partial code with the programmatically setting in an addendum edit to this post. Thanks in advance.
Please, could you send me your example? I tried to do what you are suggesting but it is still not working. I must be doing something wrong.
Thanks,
John