4

I'm developing an Azure WorkerRole(). In the Compute Emulator console, I see all Trace.WriteLine() messages, but only those generated in OnStart() seem to be persisted into storage.

My ServiceConfiguration.Local.csfg has:

<Role name="MyWorkerRole">
  <Instances count="1" />
  <ConfigurationSettings>
    <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
  </ConfigurationSettings>
</Role>

My WorkerRole.cs has:

public override void Run() {
    Trace.WriteLine("Called from Run(), where does this trace go???", "Information");

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

    DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
    dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
    dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
    DiagnosticMonitor.Start("DiagnosticsConnectionString", dmc);

    Trace.WriteLine("This trace appears in WADLogsTable", "Information");

    return base.OnStart();
}
Seth
  • 2,712
  • 3
  • 25
  • 41
  • MonAgentHost is crashing. Looks like a bug in Azure. see: http://qa.social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/3d06d8f5-adf3-47bb-8a14-d57226273d3c – Seth Aug 11 '11 at 15:37

1 Answers1

3

That looks correct - I wonder why you don't see anything. I wonder if Start is ignoring your config changes somehow. Here is some code I have used that will transfer the trace logs (I know this works):

    private static void EnableDiagnostics(int transferTime)
    {
        string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));

        RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);
        DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration();

        if (config == null)
        {
            config = DiagnosticMonitor.GetDefaultInitialConfiguration();
        }

        config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(transferTime);
        config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined;

        CrashDumps.EnableCollection(true);

        roleInstanceDiagnosticManager.SetCurrentConfiguration(config);
    }
dunnry
  • 6,858
  • 1
  • 20
  • 20
  • hey dunnry! in creating my "simpler for stackoverflow" example, I somehow made Traces work, but only inside OnStart(). I should have tested the exact code before posting - bad form on my part...very storry about that! It is very strange, because I had no other diagnostic related code active.... but somehow stubbing out my other code made it work. I still can't get Traces outside OnStart() to persist though. – Seth Aug 11 '11 at 15:16
  • Aha! The code sometimes works, and sometimes doesn't work, this looks like a bug in Azure. Looking at the console logs, something called MonAgentHost crashes (complaining about a null proxy setting!). Once it has crashed, no logs get through, before it crashes, logging works. – Seth Aug 11 '11 at 15:36
  • A workaround is described here: http://qa.social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/3d06d8f5-adf3-47bb-8a14-d57226273d3c – Seth Aug 11 '11 at 15:36