4

我正在开发一个 Azure WorkerRole()。在 Compute Emulator 控制台中,我看到了所有 Trace.WriteLine() 消息,但只有在 OnStart() 中生成的消息似乎被持久化到存储中。

我的 ServiceConfiguration.Local.csfg 有:

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

我的 WorkerRole.cs 有:

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();
}
4

1 回答 1

3

这看起来是正确的——我想知道为什么你什么都看不到。我想知道 Start 是否以某种方式忽略了您的配置更改。这是我使用的一些代码,它们将传输跟踪日志(我知道这是可行的):

    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);
    }
于 2011-08-11T15:07:23.293 回答