【问题标题】:How to log messages to the Windows Azure Storage?如何将消息记录到 Windows Azure 存储?
【发布时间】:2013-03-28 00:15:29
【问题描述】:

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

我到目前为止所做的尝试:

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

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

Trace.TraceError("My Error");

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

简而言之..我正在阅读大量文件,但无处可去。

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

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

【问题讨论】:

    标签: asp.net .net azure


    【解决方案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 的表以及进入该表的数据。

    【讨论】:

    • 感谢您的回复,看起来很有希望。我今天回家后会检查你的解决方案,然后我会给你反馈。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 2019-11-08
    • 2015-11-07
    • 1970-01-01
    相关资源
    最近更新 更多