Partager via


Diagnostics configuration requires diagnostics.wadcfgx; configuration in code is no longer supported

While preparing for tests starting on Monday I submitted some files to my Service Bus Queue and looked at the traces that was output in my Azure Table Storage. To my surprise only the errors were logged, no Information logs could be found. But I had configured tracing in my code using the code below (which is somewhat simplified in this post):

DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
config.Logs.ScheduledTransferLogLevelFilter = Microsoft.WindowsAzure.Diagnostics.LogLevel.Verbose;
DiagnosticMonitor.StartWithConnectionString("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);

It took me a while to realize what was going on! Just before leaving for Christmas vacation I had updated to Azure SDK 2.5 and only since then I had not looked at the traces much. The cause for my problem was that Azure SDK 2.5 has breaking changes which disable setting diagnistics settings using code, instead you need to use an XML config file which is deployed to Azure. See https://msdn.microsoft.com/en-us/library/azure/dn873976.aspx#BKMK_breaking for details and links to samples.

First I downloaded the diagnostics XML file from Azure using: Get-AzureServiceDiagnosticsExtension -ServiceName <<service name>>

Then I (almost) got the file below. Almost, because for some reason it was mssing the PublicConfig element and I had to add it manually to be able to upload it back to Azure. I changed the scheduledTransferLogLevelFilter to Information, that is all.

<?xml version="1.0" encoding="utf-8" ?>
<PublicConfig xmlns="https://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<WadCfg>
  <DiagnosticMonitorConfiguration overallQuotaInMB="4096">
    <DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Error" />
    <Directories scheduledTransferPeriod="PT1M">
      <IISLogs containerName="wad-iis-logfiles" />
      <FailedRequestLogs containerName="wad-failedrequestlogs" />
    </Directories>
    <WindowsEventLog scheduledTransferPeriod="PT1M">
      <DataSource name="Application!*" />
    </WindowsEventLog>
    <CrashDumps>
      <CrashDumpConfiguration processName="WaIISHost.exe" />
      <CrashDumpConfiguration processName="WaWorkerHost.exe" />
      <CrashDumpConfiguration processName="w3wp.exe" />
    </CrashDumps>
    <Logs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Information" />
  </DiagnosticMonitorConfiguration>
</WadCfg>
</PublicConfig> 

To upload the file back to Azure I used these simple Powershell commands:

Add-AzureAccount
$storage = New-AzureStorageContext -StorageAccountName <<storage Account name>> -StorageAccountKey <<key>>
Set-AzureServiceDiagnosticsExtension -ServiceName <<service name>> -StorageContext $storage -Role <<role name>> -Slot Production -DiagnosticsConfigurationPath <<full path to XML config file>>