首页 文章

Azure Diagnostic不会将日志保存在azure表中

提问于
浏览
2

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

刚创建了一个具有MVC 4 Web角色的新azure Cloud 项目,并从配置部分启用了诊断,但没有任何日志保存在azure表中 - WADLogsTable,WADDiagnosticInfrastructureLogsTable .

diagnostics.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>

ServiceDefinition.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>

ServiceConfiguration.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 .

任何帮助将不胜感激 .

谢谢

Bhavesh

2 回答

  • 3

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

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

  • 1

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

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

    有关更多信息,请参见this post .

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

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

    或者只需添加另一个名为 WaIISHost.exe.config 的配置文件(请记住将其设置为“复制到输出目录”属性) .

    在这个答案中,我假设当你在其他类中使用它时,跟踪打印正常 .

相关问题