1

我试图完成一个非常简单的任务几个小时而没有成功。我只想将消息记录到 Windows Azure 存储,以便稍后进行分析

我已经尝试过:

我已经启用了这样的诊断:

在此处输入图像描述

之后我把这条线放在我的Application_Start

Trace.TraceError("My Error");

我希望它被记录到 Windows Azure 存储中。但事实并非如此。然后我在这里读到我应该先配置DiagnosticMonitor类。但我认真地认为这个类已被弃用..因为它在Microsoft.WindowsAzure.StorageClient版本 1.7 的程序集中(其他版本是 1.8 或 2.0),当我添加对它的引用时,我的所有CloudStorageAccount引用都变得模棱两可,因为这个程序集有我已经拥有的类与其他组件Microsoft.WindowsAzure.Storage(较新)。我真的认为我不应该添加对StorageClient.

简而言之..我正在阅读很多文件并且无处可去。

你能……告诉我具体做什么吗?我会非常感激。谢谢。

PS:我在 2012 年 10 月将 VS 2012 与 Windows Azure 工具一起使用

4

1 回答 1

1

您所做的(在您的屏幕截图中)启用了诊断。您需要做的下一件事是在代码中配置诊断。为此,请按照下列步骤操作:

  1. 在 web.config 中添加以下代码行:

      <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. 在您角色的 OnStart() 方法中配置诊断。该代码仅适用于跟踪日志:

        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在您的存储帐户中创建的名称的表以及进入该表的数据。

于 2013-03-28T03:02:31.610 回答