SQL Azure Custom Logging to Windows Azure Table storage

At a Windows Azure customer of ours they keep track of changes on the tables in the SQL Azure database. This is done by a trigger, the trigger inserts the change in a table. I can not think of another solution without losing data or changes.

But the downside of this, the logging space in SQL Azure costs a lot of money. This logging is only used for an analyses of a problem and the read frequency is rather low. And btw the data is not relational. So the space for this logging data in the SQL Azure database is relatively expensive. Especially  if you compare it to Windows Azure storage.

1 Gb SQL Azure Database $ 9.99
1 Gb Windows Azure storage $ 0,15 (exclusive transactions)

(More information about Windows Azure costs)

So it makes sense to move the data as quickly as possible from SQL Azure to Windows Azure Table storage. To accomplish this I made a WorkerRole to do so.

new LoggingUtils().MoveLoggingToStorage(



This WorkerRole gets a set of data from SQL Azure:

using (SqlDataAdapter sqlDataAdapter =

    new SqlDataAdapter(

     " Delete TOP (" + _datasetSize + ") " +

     " from [Logging].[ChangeLogging] " +

     " WITH (readpast, rowlock, xlock) OUTPUT DELETED.* ",

     sqlc)   )


And then we need to append this data to a Windows Azure storage table. The logging table contains besides many fields also a TableName field. This TableName we are going to use as the PartitionKey, the UseCase describes that checks are done based on TableNames. As a RowKey I use Ticks and a Guid. The combination should be unique and there was no other data making this true.

loggingEntry.PartitionKey = dr["TableName"].ToString();
loggingEntry.RowKey = string.Format(


                  DateTime.MaxValue.Ticks - DateTime.Now.Ticks, 



As I mentioned before the Logging table should be read quickly as possible, so we need to Scale Out in two ways. More instances of the WorkerRole or more threads doing the MoveLoggingToStorage method.

Cool he. Now we need something to clean the Windows Azure Table Storage after some time. Perhaps to a zip file or Tape or whatever IT pro do Winking smile. But perhaps just deleting the rows is enough. Which is better depends on the organization.

Leave a Reply