2011-08-11 42 views
4

我正在開發Azure WorkerRole()。在計算模擬器控制檯中,我看到所有Trace.WriteLine()消息,但只有那些在OnStart()中生成的消息似乎會持久存儲。Trace.WriteLine()消息僅在Azure WorkerRole的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(); 
} 
+0

MonAgentHost崩潰。看起來像Azure中的錯誤。請參閱:http://qa.social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/3d06d8f5-adf3-47bb-8a14-d57226273d3c – Seth

回答

3

這看起來是正確的 - 我不知道你爲什麼看不到任何東西。我不知道開始是否忽略了你的配置變化。這裏有一些代碼我已經使用,將傳輸跟蹤日誌(我知道這個工程):

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); 
    } 
+0

嘿dunnry!在創建我的「簡單的stackoverflow」的例子,我不知何故使Traces工作,但只在OnStart()內。我應該在發佈之前測試確切的代碼 - 我的錯誤形式......對此非常倉促!這很奇怪,因爲我沒有其他診斷相關的代碼活躍....但不知何故殘缺我的其他代碼使它的工作。儘管如此,我仍然無法在OnStart()之外獲取Traces。 – Seth

+0

啊哈!代碼有時可用,有時不起作用,這看起來像是Azure中的一個錯誤。查看控制檯日誌,MonAgentHost崩潰(抱怨空代理設置!)。一旦它崩潰,沒有日誌通過,在它崩潰之前,日誌工作。 – Seth

+0

此處描述了一種解決方法:http://qa.social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/3d06d8f5-adf3-47bb-8a14-d57226273d3c – Seth