2013-03-28 35 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