Over a million developers have joined DZone.

Custom Logging with Windows Azure Web Sites

DZone's Guide to

Custom Logging with Windows Azure Web Sites

· Cloud Zone ·
Free Resource

Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.

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.

Join us in exploring application and infrastructure changes required for running scalable, observable, and portable apps on Kubernetes.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}