Search This Blog

Wednesday, November 17, 2010

Windows Azure Diagnostics–Where Are My Logs?

Recently I noticed that lot of developers who are just starting to use Windows Azure hit issues with diagnostics and logging. It seems I didn’t go the same path other people go, because I was able to get diagnostics running from the first time. Therefore I decided to investigate what could possibly be the problem.

I created quite simple Web application with only one Web Role and one instance of it. The only purpose of the application was to write trace message every time a button is clicked on a web page.

In the onStart() method of the Web role I commented out the following line:DiagnosticMonitor.Start("DiagnosticsConnectionString");

and added my custom log configuration:
DiagnosticMonitorConfiguration dmc =
DiagnosticMonitor.GetDefaultInitialConfiguration();
dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

DiagnosticMonitor.Start("DiagnosticsConnectionString", dmc);

Here is also the event handler for the button:

protected void BtnSmile_Click(object sender, EventArgs e)
{
    if (this.lblSmile == null || this.lblSmile.Text == "")
    {
    this.lblSmile.Text = ":)";
    System.Diagnostics.Trace.WriteLine("Smiling...");
    }
    else
    {
    this.lblSmile.Text = "";
    System.Diagnostics.Trace.WriteLine("Not smiling...");
    }
}This code worked perfectly, and I was able to get my trace messages after about a minute running the app in DevFabric.

After confirming that the diagnostics infrastructure works as expected my next goal was to see under what conditions I will see no logs generated by Windows Azure Diagnostics infrastructure. I reverted all the changes in the onStart() method and ran the application again. Not very surprisingly I saw no logs after minute wait time. Somewhere in my mind popped the value 5 mins, and I decided to wait. But even after 5 or 10, or 15 mins I saw nothing in the WADLogsTable. Apparently the problem comes from the default configuration of the DiagnosticMonitor, done through the following line :

DiagnosticMonitor.Start("DiagnosticsConnectionString");

Looking at the code I discovered that the default configuration uses

ScheduledTransferPeriodInMinutes = 0

Unfortunately this doesn’t work well with Windows Azure Diagnostics infrastructure, and is the main cause for the missing logs.

I simulated that quite easily with changing the following line in my custom configuration:

dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

to:

dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(0);

Windows Azure Diagnostics does not accept values below 1 min for transfer period. Thus you should always get diagnostics configured according to your needs, and if you don’t want to use scheduled transfers you should make sure you push out the logs in your code.

I will continue my investigation of logging in one of my subsequent posts but for now I think this will be quite helpful for people.

Update: I circled back with our developers and they reminded me that not transfering the logs by default was intentional. The reason being that you will incurr charges for the logs stored in your storage account.


Reference : http://blog.toddysm.com/2010/04/windows-azure-diagnosticswhere-are-my-logs.html

No comments: