Over a million developers have joined DZone.

Custom Logging with Windows Azure Web Sites

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

One of the features of Windows Azure Web Sites is the ability to stream logging information to the console on your development box. Both the Command-Line Tools and PowerShell bits for Windows Azure support this using the following commands:

Command-Line Tools

azure site log tail 


get-azurewebsitelog -tail 

This is pretty useful if you're trying to debug a problem, as you don't have to wait until you download the log files to see when something went wrong.

One thing that I didn't realize until recently was that not only will this stream information from the standard logs created by Windows Azure Web Sites, but it will also stream information written to any text file in theD:/home/logfiles directory of your web site. This enables you to easily log diagnostic information from your application by just saving it out to a file.

Example code snippets


Node.js doesn't really need to make use of this, as the IISNode module that node applications run under in Windows Azure Web Sites will capture stdout/stderr streams and save to file. See How to debug a Node.js application in Windows Azure Web Sites for more information.

However if you do want to log to file, you can use something like winston and use the file transport. For example:

var winston = require('winston'); winston.add(winston.transports.File, { filename: 'd:\\home\\logfiles\\something.log' }); winston.log('info', 'logging some information here'); 


error_log("Something is broken", 3, "d:/home/logfiles/errors.log"); 


I haven't gotten this fully working with Python; it's complicated. The standard log handler (RotatingFileHandler) doesn't play nice with locking in Windows Azure Web Sites. It will create a file, but it stays at zero bytes and nothing else can access it. I've been told that ConcurrentLogHandler should work, but it requires pywin32, which isn't on Windows Azure Web Sites by default.

Anyway, I'll keep investigating this and see if I can figure out the steps and do a follow-up post.


Similar to Node.js, things written using the System.Diagnostics.Trace class are picked up and logged to file automatically if logging is enabled for your web site, so there's not as much need for this with .NET applications. Scott Hanselman has a blog post that goes into a lot of detail on how this works.


If you're developing an application on Windows Azure, or trying to figure out a problem with a production application, the above should be useful in capturing output from your application code.

The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.


Published at DZone with permission of Larry Franks, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}