简体   繁体   中英

How to log messages to the Windows Azure Storage?

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 .

What I've tried to far:

I've enabled Diagnostics like this:

在此处输入图片说明

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

Trace.TraceError("My Error");

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.

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

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

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. 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> 
  2. 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); 

This should do it for diagnostics.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM