如何记录消息到Windows Azure存储? [英] How to log messages to the Windows Azure Storage?

查看:107
本文介绍了如何记录消息到Windows Azure存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图完成了几个小时都没有成功一个非常简单的任务。 我只想消息记录到Windows Azure的存储中,这样以后可以分析它

I'm trying to accomplish a very simple task for hours without success. I just want to log messages to the Windows Azure Storage so I can analyze it later.

我已经试过远:

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

I've enabled Diagnostics like this:

之后,我把此行中我的​​的Application_Start

After that I'm putting this line in my Application_Start:

Trace.TraceError("My Error");

我希望它被记录到Windows Azure存储。但事实并非如此。然后我读这里,我应该先配置 DiagnosticMonitor 类第一。但我认真地思考这个类是pcated德$ P $ ..因为它在装配 Microsoft.WindowsAzure.StorageClient 这是1.7版(其他是1.8或2.0)和当我添加一个参考吧,我所有的 CloudStorageAccount 引用变得模糊,因为该组件具有我已经与其他组件 Microsoft.WindowsAzure类。存储(更新)。我真的觉得我不应该添加的引用 StorageClient

I expect it to be logged to the Windows Azure Storage. But it's not. Then I read here that I should first configure the DiagnosticMonitor class first. But I seriously think this class is deprecated.. because it's in the assembly Microsoft.WindowsAzure.StorageClient which is version 1.7 (the others are 1.8 or 2.0) and when I add a reference to it, all my CloudStorageAccount references become ambiguous because this assembly has classes that I already have with the other assembly Microsoft.WindowsAzure.Storage (newer). I really think I shouldn't add a reference to StorageClient.

简单地说..我读了很多文件,无处可去。

Briefly.. I'm reading a lot of documents and going nowhere.

能否请你...确切地告诉我不要做什么呢?我倒是AP preciate这么多。谢谢你。

Can you please.. Tell me exactly what do do? I'd appreciate so much. Thanks.

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

PS: I'm using VS 2012 with Windows Azure Tools October 2012

推荐答案

你所做的(在你的截图)启用了诊断。你需要做的下一件事就是配置诊断在code。为此,请按照下列步骤操作:

What you've done (in your screenshot) is enabled the diagnostics. The next thing you would need to do is configure the diagnostics in your code. To do so, follow these steps:

  1. 添加了code以下行web.config中:

  1. Add the following lines of code in 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>

  • 在配置你的角色的的OnStart()方法诊断。在code是仅用于跟踪日志:

  • Configure diagnostics in your role's OnStart() method. The code is only for trace logs:

        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诊断模块在旧的存储客户端库的依赖性(<$ C C $> Microsoft.WindowsAzure.StorageClient.dll )。所以,你需要确保这个库是在你的项目中引用。您可以从Ç手动添加引用:\ Program Files文件\微软的SDK \ Windows Azure的\ .NET SDK \ 2012-10 \ REF 文件夹。这种混乱会,如果您同时使用旧的存储客户端库和新的人来( Microsoft.WindowsAzure.Storage.dll )。因此,你需要确保CloudStorageAccount对象正常范围。

    Regarding the confusion over older and newer storage client library: Currently Windows Azure Diagnostics module has a dependency on older storage client library (Microsoft.WindowsAzure.StorageClient.dll). So you would need to ensure that this library is referenced in your project. You can add the reference manually from C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-10\ref folder. The confusion would come if you're using both old storage client library and the new one (Microsoft.WindowsAzure.Storage.dll). Thus you would need to ensure that CloudStorageAccount object is properly scoped.

    在一切都已经安装,你应该能够看到一个表格进行存储帐户和数据进来到该表中创建名为 WADLogsTable

    Once everything has been setup, you should be able to see a table by the name WADLogsTable created in your storage account and data coming in into that table.

    这篇关于如何记录消息到Windows Azure存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆