Sunday, August 30, 2009

Azure Logs

The convinient RoleManager.WriteToLog static method provides way to write event logs for your clouded application. In the reference:
you will find that the allowed values for "eventLogName" are:
Critical, Error, Warning, Information, Verbose

It's a good idea to have them handy :)

Here is a complete How-to guide for writing and reading logs:

I will just add that there is a great tool at CodePlex:
Which is visual storage explorer. Something that I missed is that account configuration requires restart of the application (at least for me). If you are going to wander how to configure your cloud storage - just enter your cloud storage account name (without http://, and without, or, etc.) and your primary or secondary key - it works with both keys.

Azure Worker Roles

Have you tried it yet ?
It is a background worker process, jsut like a windows service. So you can create your background working processes just like you used with Windows Service. It is very simple to implement:

public class WorkerRole : RoleEntryPoint
public override void Start()
// This is a sample worker implementation. Replace with your logic.
RoleManager.WriteToLog("Information", "Worker Process entry point called");
while (true)
RoleManager.WriteToLog("Information", "Working");
public override RoleStatus GetHealthStatus()
// This is a sample worker implementation. Replace with your logic.
return RoleStatus.Healthy;

As simple as that. Of course you can have your System.Timers.Timer instance or more and schedule your processing logic to start up at regular periods.

Azure WebRole and Custom Error Handlers

A useful article on how to use custom handlers in the cloud:

The main idea is that Azure is runnin on IIS7, so you have the power to plug-in into the integrated pipline mode.

In short:

< errormode="Custom">
< statuscode="404">
< statuscode="404" responsemode="ExecuteURL" path="/page-not-found.aspx">
< /httpErrors >
< /system.webServer >

Put the configuration in system.webServer, insted of in system.web.

I would also add a handler for 400 status code. This is if you are making some custom http handlers.

How to use SQL Azure

If you want to play with SQL Azure it is little tricky. You cannot use SQL Server management Studio. However you can connect using ADO.NET. One option is to develop small app that does basic things like listing tables, enables editing tables etc, which actually is not that hard - to cover basic functionality.
Until then, the smoothest way I found is usign the SQLCmd tool.
Better described here:
However this is the "quick-start":

The key here is that you must use MY_USERNAME@MY_SERVER_NAME !
For example, if your server name is h38ssfjeiwh201, your username is admin and connecting to sample_db your connection would be.
sqlcmd -S -U admin@h38ssfjeiwh201 -d sample_db

Also good point is that you must explicitly specify DataBase name to use, since AzureSQL CTP still does not support USE DataBaseName command.

Good luck and happy times with Sql Azure!

Azure Worker Role config settings app.config

Recently playing with Azure July CTP I stumbled upon an issue which appeared to be known.
The thing that might drive you crazy is that the Publishing wizard does not apply settings from App.Config file. So basically your deployed worker process will have no idea about configuration settings.
It seemed to be a known issue and there are some discussions over here:

other thread:

The solution is trivial:
You have to add an environment variable to your user account:
Key: AddAppConfigToBuildOutputs
Value: true
And you need to restart Visual Studio for the change to take place.