2

只需检查 windows azure sdk 2.0 中引入的新功能 - 启用诊断。

刚刚使用 MVC 4 Web 角色创建了一个新的天蓝色云项目,并从配置部分启用了诊断,但没有任何日志保存在天蓝色表 - WADLogsTable、WADDiagnosticInfrastructureLogsTable 上。

诊断程序.wadcfg

<?xml version="1.0" encoding="utf-8"?>
<DiagnosticMonitorConfiguration configurationChangePollInterval="PT1M" overallQuotaInMB="4096" xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
  <DiagnosticInfrastructureLogs />
  <Directories>
    <IISLogs container="wad-iis-logfiles" />
    <CrashDumps container="wad-crash-dumps" />
  </Directories>
  <Logs bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" />
  <WindowsEventLog bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose">
    <DataSource name="Application!*" />
  </WindowsEventLog>
</DiagnosticMonitorConfiguration>

服务定义.csdef

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureWebApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2013-03.2.0">
  <WebRole name="MvcWebApp" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
  </WebRole>
</ServiceDefinition>

服务配置.Cloud.cscfg

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="AzureWebApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="3" osVersion="*" schemaVersion="2013-03.2.0">
  <Role name="MvcWebApp">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

WebRole.cs -- 来自 MVC 应用程序

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace MvcWebApp
{
    public class WebRole : RoleEntryPoint
    {
        public override void Run()
        {
            // This is a sample webrole implementation. Replace with your logic.

            while (true)
            {
                Thread.Sleep(10000);
                Trace.WriteLine("Working", "Information");
            }
        }

        public override bool OnStart()
        {
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            Trace.WriteLine("Starting Web Role ...", "Information");

            return base.OnStart();
        }
    }
}

我期待 Trace.WriteLine 错误,即“正在启动 Web 角色 ...”和“正在工作”到保存在 azure 表 - WADLogsTable 中。

任何帮助将不胜感激。

谢谢

巴韦什

4

2 回答 2

3

diagnostics.wadcfg如果部署文件, 则无需将任何自定义检测代码添加到 OnStart() 方法。

问题在于ServiceConfiguration.Cloud.cscfg包含的文件"DevelopmentStorage=true"——将其替换为您的真实存储帐户或确保您的部署工具执行此操作。

于 2013-06-03T18:03:42.073 回答
1

您正在尝试从RoleEntryPoint对象写入跟踪线。

WebRole实例在与您的应用程序进程不同的进程中运行,因此您的 web.config 中的配置不会影响它。

有关更多信息,请参阅此帖子

您可以手动设置诊断侦听器:

public class WebRole : RoleEntryPoint
{
    public override void Run()
    {
        var listener = new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener();
        Trace.Listeners.Add(listener);
    }
}

或者简单地添加另一个名为WaIISHost.exe.config的配置文件(记住将其设置为复制到输出目录属性)。

在这个答案中,我假设当您在其他类中使用跟踪打印时,它对您来说工作得很好。

于 2013-06-14T12:33:18.487 回答