简体   繁体   中英

Unable to enable AzureServiceDiagnosticsExtension for Cloud Service on Azure

I am unable to set the diagnostic extension for my cloud service via a powershell command. I am getting following error:

New-AzureServiceDiagnosticsExtensionConfig : The element StorageAccount 
doesn't match the storage account name provided in the cmdlet arguments. It is 
recommended to not use the element StorageAccount as it is automatically set 
by the cmdlet.

Powershell Command to enable diagnostics for Cloud Service

$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Set-AzureServiceDiagnosticsExtension -StorageContext $storageContext -DiagnosticsConfigurationPath $diagnosticFileLocation -ServiceName $serviceName

My diagnostic file looks like

<?xml version="1.0" encoding="utf-8"?>
<DiagnosticsConfiguration  xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
  <PublicConfig>
    <WadCfg>
      <DiagnosticMonitorConfiguration overallQuotaInMB="4096">
        <DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Error"/>
        <Logs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Error" />
        <Directories scheduledTransferPeriod="PT1M">
          <IISLogs containerName ="wad-iis-logfiles" />
          <FailedRequestLogs containerName ="wad-failedrequestlogs" />
        </Directories>
        <WindowsEventLog scheduledTransferPeriod="PT1M" >
          <DataSource name="Application!*" />
        </WindowsEventLog>
        <CrashDumps containerName="wad-crashdumps" dumpType="Mini">
          <CrashDumpConfiguration processName="WaIISHost.exe"/>
          <CrashDumpConfiguration processName="WaWorkerHost.exe"/>
          <CrashDumpConfiguration processName="w3wp.exe"/>
        </CrashDumps>
        <PerformanceCounters scheduledTransferPeriod="PT1M">
          <PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
          <PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />
        </PerformanceCounters>
      </DiagnosticMonitorConfiguration>
    </WadCfg>
  </PublicConfig>
  <PrivateConfig>
    <StorageAccount name="" key="" endpoint="" />
  </PrivateConfig>
  <IsEnabled>true</IsEnabled>
</DiagnosticsConfiguration>

I think the problem is that you are having an empty Storage Accout tag in the Diagnostics Configuration file(.wadcfgx).

If you deploy your cloud service through Visual Studio, you can make few changes to fix the bug: (Since the diagnostics connection string in the .cscfg file takes precedence over the storage account in the .wadcfgx file, suggest you introduce the storage account name in ".cscfg" rather than ".wadcfgx")

  • First, introduce the storage account name in the connection string of the “.cscfg” file.

      <ConfigurationSettings> <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https; AccountName=TestAccountName; AccountKey=abcdefg****************==" /> 
  • Second, remove the <StorageAccount/> tag from the diagnostics configuration file.

Refer to https://pawanpalblog.wordpress.com/2015/10/26/set-azureservicediagnosticsextension/ and https://azure.microsoft.com/en-us/documentation/articles/vs-azure-tools-diagnostics-for-cloud-services-and-virtual-machines/ for more details.

Hope this helps.

Before you enable the diagnostic extension, you need to finish 3 prerequisites.

  1. Assign a role to the cloud service. WorkerRole1 as a example. Refer to cloud-services-dotnet-diagnostics Step 1: Create a Worker Role. Create a cloud service and a workerRole. Set a workerrole for your cloud service in the Publish page. 在此处输入图片说明

  2. Note the Environment value from the above image. You will use it in -Slot Staging

  3. Sort your diagnostic file. Use the solution from @Derek. Change to <PrivateConfig><ConfigurationSettings><Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=; AccountKey=" /></ConfigurationSettings> </PrivateConfig>

Run the code(2 steps):

$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

$role_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole1" -DiagnosticsConfigurationPath $diagnosticFileLocation -StorageContext $storageContext 

Set-AzureServiceDiagnosticsExtension -DiagnosticsConfiguration $role_diagconfig  -ServiceName $service_name -Slot Staging

Or 1 step simplify :

$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

Set-AzureServiceDiagnosticsExtension -StorageContext $storageContext -DiagnosticsConfigurationPath $diagnosticFileLocation -ServiceName $serviceName -Slot Staging -Role WorkerRole1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM