2013-06-03 33 views
2

只需檢查Windows Azure sdk 2.0中引入的新功能 - 啓用診斷。Azure Diagnostic不會將日誌保存在天藍色的表中

剛剛使用MVC 4 Web Role創建了一個新的Azure雲項目,並從配置部分啓用了診斷,但沒有一個日誌保存在Azure表上 - WADLogsTable,WADDiagnosticInfrastructureLogsTable。

diagnostics.wadcfg

<?xml version="1.0" encoding="utf-8"?> 
<DiagnosticMonitorConfiguration configurationChangePollInterval="PT1M" overallQuotaInMB="4096" xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"> 
    <DiagnosticInfrastructureLogs /> 
    <Directories> 
    <IISLogs container="wad-iis-logfiles" /> 
    <CrashDumps container="wad-crash-dumps" /> 
    </Directories> 
    <Logs bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" /> 
    <WindowsEventLog bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose"> 
    <DataSource name="Application!*" /> 
    </WindowsEventLog> 
</DiagnosticMonitorConfiguration> 

ServiceDefinition.csdef中

<?xml version="1.0" encoding="utf-8"?> 
<ServiceDefinition name="AzureWebApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2013-03.2.0"> 
    <WebRole name="MvcWebApp" vmsize="Small"> 
    <Sites> 
     <Site name="Web"> 
     <Bindings> 
      <Binding name="Endpoint1" endpointName="Endpoint1" /> 
     </Bindings> 
     </Site> 
    </Sites> 
    <Endpoints> 
     <InputEndpoint name="Endpoint1" protocol="http" port="80" /> 
    </Endpoints> 
    <Imports> 
     <Import moduleName="Diagnostics" /> 
    </Imports> 
    </WebRole> 
</ServiceDefinition> 

ServiceConfiguration.Cloud.cscfg

<?xml version="1.0" encoding="utf-8"?> 
<ServiceConfiguration serviceName="AzureWebApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="3" osVersion="*" schemaVersion="2013-03.2.0"> 
    <Role name="MvcWebApp"> 
    <Instances count="1" /> 
    <ConfigurationSettings> 
     <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> 
    </ConfigurationSettings> 
    </Role> 
</ServiceConfiguration> 

WebRole.cs - 從MVC應用

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Linq; 
using System.Threading; 
using Microsoft.WindowsAzure; 
using Microsoft.WindowsAzure.Diagnostics; 
using Microsoft.WindowsAzure.ServiceRuntime; 

namespace MvcWebApp 
{ 
    public class WebRole : RoleEntryPoint 
    { 
     public override void Run() 
     { 
      // This is a sample webrole implementation. Replace with your logic. 

      while (true) 
      { 
       Thread.Sleep(10000); 
       Trace.WriteLine("Working", "Information"); 
      } 
     } 

     public override bool OnStart() 
     { 
      // For information on handling configuration changes 
      // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. 

      Trace.WriteLine("Starting Web Role ...", "Information"); 

      return base.OnStart(); 
     } 
    } 
} 

我期待Trace.WriteLine錯誤,即「啓動Web角色...」和「工作」到保存在天藍色表 - WADLogsTable中。

任何幫助將不勝感激。

感謝

Bhavesh

+0

有人可以請求幫助,爲什麼我的簡單trace.Writeline沒有將日誌存儲到Azure表存儲。 – user1754675

+0

診斷有一個很長的故事已知的計算仿真器中不工作的問題。在本地運行時,我幾乎從未成功將日誌從診斷監視器中取出!但它在部署時起作用。對於本地跟蹤/診斷會話,您可以打開['Compute Emulator UI'](http://blogs.staykov.net/2013/05/windows-azure-basicscompute-emulator.html),導航到「Instance」想要「監視」並觀察輸出的「角色」。 – astaykov

+0

它在MSDN中爲Q&A部分提供了檢查。http://msdn.microsoft.com/en-us/library/azure/dn186185.aspx – Bibhu

回答

3

你不需要任何自定義的儀器代碼添加到您的OnStart()方法,如果你部署diagnostics.wadcfg文件。

問題在於包含"DevelopmentStorage=true"ServiceConfiguration.Cloud.cscfg文件 - 將其替換爲您的真實存儲帳戶或確保您的部署工具執行此操作。

+0

我在本地模擬器中運行應用程序,所以我的local.cscfg和cloud.cscfg是相同的。在將我的web角色發佈到雲之前,我將更新配置,但現在我想查看本地存儲中的日誌,我無法查看。 我注意到存儲表中的「WADWindowsEventLogsTable」表,但沒有註冊WADLogsTable。 – user1754675

1

您正在嘗試從RoleEntryPoint對象寫入跡線。

WebRole實例運行在與應用程序進程不同的進程中,因此web.config中的配置不會影響它。

請參閱this post瞭解更多信息。

你可以手動設置診斷監聽器:

public class WebRole : RoleEntryPoint 
{ 
    public override void Run() 
    { 
     var listener = new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener(); 
     Trace.Listeners.Add(listener); 
    } 
} 

或者乾脆添加一個名爲WaIISHost.exe.config另一個配置文件(記得設置它複製到輸出目錄屬性)。

在這個答案中,我假設當您在其他課程中使用它時,跟蹤打印對您來說工作正常。

相關問題