Tracing Windows Azure Apps to Storage

So one of the things I like to do, all of the time, is trace. It started when I was a little child, and the rest of the kids could draw really good and stuff, and I couldn’t, so I would get pictures of horses and trace around them…

Now that I’m older, I still can’t draw, let alone code, very well, so I still trace.

In my Windows Azure apps, I like to trace to my own log files, it’s not the RoleManager.WriteToLog isn’t good, but I have code from other apps that already uses the trace infrastructure and pragma concepts, so having calls to Trace.WriteLine simply work as normal is a big attraction.

So how do you do this?

First, simply create your own custom trace listener and have it write to Windows Azure Storage.


Then load it into your role.


And now when you call the Trace.WriteLine for example, it will call your custom trace handler too.


Also, the sample below also has a little UI web role so you can see what’s being logged!


You can find the zip archive of the project here. I’ve scrubbed the .cscfg file so you can add your own links into it for your storage account and test URL for the pic it downloads.

Enjoy :)