c# - Azure 诊断不会创建 WADLogsTable

标签 c# wcf azure diagnostics webrole

我想使用 NLog 和 Azure Diagnostics 将日志记录添加到现有的 azure 云服务,我完成了此处描述的所有步骤:http://msdn.microsoft.com/en-us/library/azure/dn482131.aspx

但是,不幸的是,在测试云服务时,未创建 WADLogsTable 表存储,并且此处不存储任何信息。不在本地开发存储上,也不在 Azure 上。

诊断.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" directoryQuotaInMB="1024" />
    <CrashDumps container="wad-crash-dumps" />
  </Directories>
  <Logs bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" />
  <PerformanceCounters bufferQuotaInMB="512">
    <PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
  </PerformanceCounters>
  <WindowsEventLog bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose">
    <DataSource name="Application!*" />
  </WindowsEventLog>
</DiagnosticMonitorConfiguration>

ServiceConfiguration.Local.csfg(与云相同,只是使用正确的表存储帐户)

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

服务定义.csdef

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AAService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-01.2.3">
  <WebRole name="Web.Services.AAService" vmsize="ExtraSmall">
    <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>
    <LocalResources>
      <LocalStorage name="Web.Services.AAService.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" />
    </LocalResources>
  </WebRole>
</ServiceDefinition>

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());

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

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            return base.OnStart();
        }

云服务web.config还有:

<system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>

有人知道为什么这不会产生任何跟踪日志吗?我在应用程序确实经过的许多地方调用了 Trace.WriteLine(),但仍然没有 WADLogsTable。

感谢您的帮助

最佳答案

删除 OnStart 中的所有诊断*代码。 <Import moduleName="Diagnostics" />您的 csdef 中将自动启动诊断代理,并且诊断代理将从 .wadcfg 中读取设置。 OnStart 中的代码是不必要的,并且由于加载 WAD 配置的优先顺序,它会覆盖 wadcfg 设置。

另请注意,如果您尝试更新现有云服务,则需要首先删除 Blob 存储中的 XML 文件。如果 Blob 存储中已存在文件,则诊断代理将忽略 .wadcfg 设置。您要查找的文件位于 wad-control-container 中,并将以部署 ID 和角色名称命名。

关于c# - Azure 诊断不会创建 WADLogsTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25210422/

相关文章:

c# - http工作时如何测试WCF net.tcp?

c# - 当 SSL 不可行时,最好的 WCF 安全模式是什么

c# - 从作为 Azure Web App 托管的 ASP.NET 5 应用程序进行日志记录

powershell - Azure 帐户级 SAS token : Possible to Have a Policy?

c# - .NET 中 NSOperationQueue 的等价物

c# - 我可以扩展 Button 以添加 Right Click 事件,同时保持图形副作用吗?

c# - 通过System.Linq在C#中获取元素的属性名称和值

运行批处理文件的 C# 代码在控制台应用程序中工作,但相同的代码在 WCF 服务中不起作用

c# - 可以存储在列表中的元素是否有限制?

azure - Windows Azure RDP/FTP