1

由于某种原因,我在 Azure 中使用诊断时遇到错误。我的(WCF)WebRole 的代码是:

public override bool OnStart()
    {
        // To enable the AzureLocalStorageTraceListner, uncomment relevent section in the web.config  
        DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
        diagnosticConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
        diagnosticConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
        diagnosticConfig.Directories.BufferQuotaInMB = 256;

        // Start diagnostics
        DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfig);

        // Write trace line
        Trace.WriteLine("CUSTUM TRACE MESSAGE");

        // Start instance
        return base.OnStart();
    }

我的 Web.config 文件如下所示:

<?xml version="1.0"?>
<configuration>
  <configSections>
  </configSections>
  <system.diagnostics>     
    <sharedListeners>
      <add name="AzureLocalStorage" type="WCFServiceWebRole1.AzureLocalStorageTraceListener, WCFServiceWebRole1"/>
    </sharedListeners>
    <sources>
      <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
        <listeners>
          <add name="AzureLocalStorage"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
        <listeners>
          <add name="AzureLocalStorage"/>
        </listeners>
      </source>
    </sources>
    <trace autoflush="true">
      <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> 
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

在计算模拟器中,我看到以下错误:

[MonAgentHost] Output: Monitoring Agent Started
[Diagnostics]: Starting configuration channel polling
[MonAgentHost] Error: MA EVENT: 2012-06-06T10:01:20.111Z
[MonAgentHost] Error:     2
[MonAgentHost] Error:     6396
[MonAgentHost] Error:     6624
[MonAgentHost] Error:     NetTransport
[MonAgentHost] Error:     0
[MonAgentHost] Error:     x:\btsdx\215\services\monitoring\shared\nettransport\src\xblobconnection.cpp
[MonAgentHost] Error:     XBlobConnection::PutBytesXBlob
[MonAgentHost] Error:     1621
[MonAgentHost] Error:     ffffffff80050023
[MonAgentHost] Error:     0
[MonAgentHost] Error:     
[MonAgentHost] Error:     Failed to send bytes to XContainer wad-tracefiles

此错误重复多次。“wad-tracefiles”容器由 AzureLocalStorageTraceListener 类中的以下代码添加:

public static DirectoryConfiguration GetLogDirectory()
    {
        DirectoryConfiguration directory = new DirectoryConfiguration();
        directory.Container = "wad-tracefiles";
        directory.DirectoryQuotaInMB = 10;
        directory.Path = RoleEnvironment.GetLocalResource("WCFServiceWebRole1.svclog").RootPath;
        return directory;
    }

为什么在这种情况下写入跟踪消息会失败?当我使用 Azure 存储资源管理器查看存储时,我看到的唯一表是 WADDirectoriesTable 而不是 WADLogsTable。确实创建了“wad-tracefiles”blob,但这不是我应该从我的代码中找到跟踪消息的地方。

任何人,任何想法?任何帮助表示赞赏!

4

2 回答 2

1

您的第一个问题是您没有使用 SetCurrentConfiguration() 和 GetDefaultInitialConfiguration() 来最终节省传输时间和日志级别。您必须使用这些 API 的集合,如下所示:

GetDefaultInitialConfiguration() 
SetCurrentConfiguration() 

或者

GetCurrentConfiguration()
SetCurrentConfiguration()

因此,基于以下行的配置将不会保存在诊断配置中: diagnosticConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());

使用上述建议,然后看看会发生什么。

我还建议只创建一个非常简单的 Web 或辅助角色 hello world 示例,并通过启用 Azure 诊断来添加一般 TRACE 消息,以查看这是否会给您带来任何错误。这将证明您的 SDK 安装或 Azure 存储模拟器是否有任何问题。

于 2012-06-06T17:59:32.563 回答
0

Thank you for your reply! The project I am using is a really simple WebRole with only one trace message so I can not strip any code out.

I tried your suggestion and you are right, I do not get any error messages anymore with the following code:

public override bool OnStart()
    {
        setDiagnostics();

        Trace.WriteLine("CUSTUM TRACE MESSAGE");

        // Start instance
        return base.OnStart();
    }

    private void setDiagnostics()
    {
        // Get diagnostics connectionstring
        string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
        CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));

        // Get the diagnostics configuration of the deployment and its role instances that are currently running
        DeploymentDiagnosticManager deploymentDiagnosticManager = new DeploymentDiagnosticManager(cloudStorageAccount, RoleEnvironment.DeploymentId);
        RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
            RoleEnvironment.DeploymentId,
            RoleEnvironment.CurrentRoleInstance.Role.Name,
            RoleEnvironment.CurrentRoleInstance.Id);

        // Load diagnostics configuration
        DiagnosticMonitorConfiguration diagConfig = roleInstanceDiagnosticManager.GetCurrentConfiguration();

        // Get the default value if there is no config yet
        if (diagConfig == null)
            diagConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();

        // Enable EventLogs
        diagConfig.WindowsEventLog.DataSources.Add("Application!*");
        diagConfig.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D);
        diagConfig.WindowsEventLog.BufferQuotaInMB = 128;

        // Failed Request Logs
        diagConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
        diagConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D);
        diagConfig.Directories.BufferQuotaInMB = 128;

        // Crash Dumps
        CrashDumps.EnableCollection(true);

        // Set new configuration
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);

        // Start the DiagnosticMonitor
        DiagnosticMonitor.Start(wadConnectionString, diagConfig);
    }

When I look in which tables are present in the Azure Storage Explorer I only see the "WADDirectoriesTable" and the "WADWindowsEventLogsTable". Trace messages should come in the "WADLogsTable" right? So I see the Trace message in the Compute Emulator but I do not see them in my storage... any ideas why?

于 2012-06-07T06:45:09.600 回答