Custom logging with Windows Azure web sites

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 the D:/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.

Comments (2)

  1. Stephan says:

    Thanks for the article. Have you found a nice way to log with Python?

  2. Larry Franks says:

    Hi Stephan, not an easy/great way. ConcurrentLogHandler apparently works, but since it requires pywin32, you have to use a sort of non-standard approach and include a bunch of stuff.…/DjangoWAWSLogging is a project that demonstrates how to get this up and running, but there's no instructions with it. Basically the DjangoWAWSLogging sub-directory contains the web site and all the required bits. If you'll notice, there's an ENV folder with a huge amount of files in it. This is the extra magic that makes it work. Even then there are some caveats, like not being able to download the logs, but it does allow streaming of the logs.

Skip to main content