2013-03-28 21 views
1

我試圖完成一個非常簡單的任務幾個小時沒有成功。 我只想將消息記錄到Windows Azure存儲,以便日後可以分析它如何將消息記錄到Windows Azure存儲?

我已經試過遠:

我已經啓用診斷是這樣的:

enter image description here

之後,我把此行中我Application_Start

Trace.TraceError("My Error"); 

我希望它被記錄到Windows Azure存儲。但事實並非如此。然後我讀here,我應該首先配置DiagnosticMonitor類。但我認真地認爲這個類是不推薦使用的..因爲它是在組件​​這是1.7版(其他1.8或2.0),當我添加一個引用時,所有我的CloudStorageAccount引用變得含糊不清,因爲這個程序集有類我已經與其他組件Microsoft.WindowsAzure.Storage(更新)。我真的認爲我不應該添加對StorageClient的引用。

簡而言之,我正在閱讀大量文檔並且無處可去。

你可以請..告訴我具體做什麼?我非常感激。謝謝。

PS:我使用VS 2012年的Windows Azure工具2012年10月

回答

1

你所做的(在你的屏幕截圖)啓用了診斷。接下來你需要做的是在代碼中配置診斷。爲此,請按照下列步驟操作:

  1. 添加以下代碼行web.config中:在你的角色的的OnStart()方法

    <system.diagnostics> 
    <trace> 
        <listeners> 
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> 
         <filter type=""/> 
        </add> 
        </listeners> 
    </trace></system.diagnostics> 
    
  2. 配置診斷。該代碼僅用於跟蹤日誌:

    DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration(); 
    
        // Set an overall quota of 8GB. 
        config.OverallQuotaInMB = 4096; 
        // Set the sub-quotas and make sure it is less than the OverallQuotaInMB set above 
        config.Logs.BufferQuotaInMB = 512; 
        TimeSpan myTimeSpan = TimeSpan.FromMinutes(2); 
        config.Logs.ScheduledTransferPeriod = myTimeSpan;//Transfer data to storage every 2 minutes 
    
        // Filter what will be sent to persistent storage. 
        config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined;//Transfer everything 
        // Apply the updated configuration to the diagnostic monitor. 
        // The first parameter is for the connection string configuration setting. 
        DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config); 
    

這應該用於診斷做。

關於對較舊和較新的存儲客戶端庫的混淆:目前Windows Azure診斷模塊對較舊的存儲客戶端庫(Microsoft.WindowsAzure.StorageClient.dll)具有依賴性。所以你需要確保這個庫在你的項目中被引用。您可以從C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-10\ref文件夾手動添加參考。如果您同時使用舊的存儲客戶端庫和新的存儲庫(Microsoft.WindowsAzure.Storage.dll),則會產生混淆。因此您需要確保CloudStorageAccount對象的範圍是正確的。

完成所有設置後,您應該能夠看到在您的存儲帳戶中創建的名稱爲WADLogsTable的表格以及進入該表格的數據。

+0

感謝您的回覆,看起來很有希望。我今天回家後會檢查你的解決方案,然後我會給你反饋。再次感謝。 – 2013-03-28 10:41:26

+0

That works ..非常感謝你! – 2013-03-30 08:06:31

相關問題