How Can I see my Diagnostics Trace of my Azure Worker Role?

Martin N. Rabaglia picture Martin N. Rabaglia · Aug 15, 2011 · Viewed 6.9k times · Source

I have a doubt with Azure Trace Logs. I have a Worker Role and I want to log certain events,

When we deploy the application locally we can read the Trace using Cerebrata Cerebrata Cloud Storage. But when we deploy to staying or production we can't. We are using the same Storage accounts.

Worker Code:

public override bool OnStart()
{
        // Set the maximum number of concurrent connections
        ServicePointManager.DefaultConnectionLimit = 12;

        DiagnosticMonitorConfiguration diagnosticMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
        diagnosticMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
        diagnosticMonitorConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
        CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        DiagnosticMonitor diagnosticMonitor = DiagnosticMonitor.Start(cloudStorageAccount, diagnosticMonitorConfiguration);
        return base.OnStart();
    }

     public override void Run()
    {
        // This is a sample worker implementation. Replace with your logic.
        Trace.WriteLine("UpdateWorker entry point called", "Information");

        while (true)
        {
            Thread.Sleep(5000);
            Trace.WriteLine("Working", "Information" + DateTime.Now);
        }
    }

App.config

        <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
        <system.diagnostics>
          <trace>
            <listeners>
              <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                  name="AzureDiagnostics">
                <filter type="" />
              </add>
            </listeners>
          </trace>
        </system.diagnostics>
      </configuration>

Where should we look? Is something wrong with this code?

Thanks!

Answer

Vidar Kongsli picture Vidar Kongsli · Aug 16, 2011

I think the problem is on the line with

CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;

You are referencing the local development storage on your computer, which will not be available when running in the cloud. Use a proper connection string to Azure Storage and use that for writing the logs to.