如何查看Azure工作者角色的诊断跟踪?

时间:2011-08-15 20:02:08

标签: .net logging azure trace diagnostics

我对Azure Trace Logs有疑问。 我有一个工人角色,我想记录某些事件,

当我们在本地部署应用程序时,我们可以使用Cerebrata Cerebrata Cloud Storage读取Trace。 但是,当我们部署到停留或生产时,我们不能。我们使用相同的存储帐户。

工人代码:

public override bool OnStart()
{
        // Set the maximum number of concurrent connections
        ServicePointManager.DefaultConnectionLimit = 12;

        DiagnosticMonitorConfiguration diagnosticMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
        diagnosticMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
        diagnosticMonitorConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
        CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        DiagnosticMonitor diagnosticMonitor = DiagnosticMonitor.Start(cloudStorageAccount, diagnosticMonitorConfiguration);
        return base.OnStart();
    }

     public override void Run()
    {
        // This is a sample worker implementation. Replace with your logic.
        Trace.WriteLine("UpdateWorker entry point called", "Information");

        while (true)
        {
            Thread.Sleep(5000);
            Trace.WriteLine("Working", "Information" + DateTime.Now);
        }
    }

的App.config

        <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
        <system.diagnostics>
          <trace>
            <listeners>
              <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                  name="AzureDiagnostics">
                <filter type="" />
              </add>
            </listeners>
          </trace>
        </system.diagnostics>
      </configuration>

我们应该在哪里看?这段代码有问题吗?

谢谢!

2 个答案:

答案 0 :(得分:4)

我认为问题在于

CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;

您正在引用计算机上的本地开发存储,这在云中运行时将无法使用。使用适当的连接字符串连接到Azure存储,并使用该字符串将日志写入。

答案 1 :(得分:0)

您可能忘记添加Azure存储连接字符串 “ServiceConfiguration.cscfg”文件

<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=<Storage Account Name>;AccountKey=<Storage Account Key>" />
</ConfigurationSettings>