Azure PowerShell: Enable Application Diagnostics and Site Diagnostics

前端 未结 3 528
既然无缘
既然无缘 2021-01-14 21:17

I am configuring Diagnostics & IIS Logs for Azure Websites. Azure Manage Portal shows options to store Application Diagnostics to Azure Table Storage:

相关标签:
3条回答
  • 2021-01-14 21:53

    This is apparently fixed in the latest (as of 3/21/2016) release of the Azure PowerShell cmdlets. You can now specify the table/container name, e.g.

    Enable-AzureWebsiteApplicationDiagnostic -Name <mysite> -Slot production -StorageAccountName <storageAccountName> -BlobStorage -StorageBlobContainerName <containerName> -LogLevel Verbose

    Enable-AzureWebsiteApplicationDiagnostic -Name <mysite> -Slot production -StorageAccountName <storageAccountName> -TableStorage -StorageTableName <tableName> -LogLevel Verbose

    0 讨论(0)
  • 2021-01-14 21:57

    After you enable the table diagnostics, try setting this app_setting for the SAS URL to your table:

    DIAGNOSTICS_AZURETABLESASURL

    Example:

    $site = get-azurewebsite mysite
    $site.AppSettings.Add("DIAGNOSTICS_AZURETABLESASURL", "<YOUR TABLE SAS URL>")
    set-azurewebsite $site.Name -AppSettings $site.AppSettings
    

    You can find out more about the SAS URLs here: http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx

    You can't just set the table name because it needs more information for security purposes to access the table as fully as it needs to for writing data.

    0 讨论(0)
  • 2021-01-14 22:07

    Now Enable-AzureWebsiteApplicationDiagnostic does not work. See Enable-AzureWebsiteApplicationDiagnostic: specify storage account name?

    This was used (thanks to this: Is there a way to enable application logging to blob for azure app service using PowerShell or ARM template?)

    Also one can find very useful to use https://resources.azure.com and Powershell tab there.

        function setLogging(
            [string]$groupName,
            [string]$siteName,
            [string]$saName,
            [string]$webAppBlobContainerName,
            [string]$iisBlobContainerName
        ) {
    
            # This script sets application and IIS logging to Azure Blob Storage. Disables file system logging
            # get Storage Account 
            $getSaArgs = @{
                ResourceGroupName = $groupName
                Name = $saName
            }
            $sa = Get-AzureRmStorageAccount @getSaArgs
            function getSasToken ($containerName, $sa){ 
                $newSCArgs = @{
                    Context = $sa.Context
                    Name = $containerName
                }
                New-AzureStorageContainer @newSCArgs -ErrorAction Ignore | out-null
                $newTokenArgs = @{
                    Context = $sa.Context
                    Name = $containerName
                    Permission = 'rwdl'
                    StartTime = (Get-Date).Date
                    ExpiryTime = (Get-Date).Date.AddYears(200)
                    FullUri = $true
                }
                New-AzureStorageContainerSASToken @newTokenArgs
            }
            $appSaToken = (& getSasToken -containerName $webAppBlobContainerName -sa $sa)
            $iisSaToken = (& getSasToken -containerName $iisBlobContainerName -sa $sa)
    
            # get the log setting
            $getResourceArgs = @{
                ResourceGroupName = $groupName
                ApiVersion = '2018-02-01'
                ResourceType = 'Microsoft.Web/sites/config' 
                ResourceName = ($siteName + "/logs")
            }
            $logSetting = Get-AzureRmResource @getResourceArgs
            $logSetting.Properties.applicationLogs.azureBlobStorage.level = "Verbose" 
            $logSetting.Properties.applicationLogs.azureBlobStorage.sasUrl = $appSaToken.ToString()
            $logSetting.Properties.applicationLogs.azureBlobStorage.retentionInDays = 0
            $logSetting.Properties.applicationLogs.fileSystem.level = "Off"
            $logSetting.Properties.httpLogs.azureBlobStorage.sasUrl = $iisSaToken.ToString()
            $logSetting.Properties.httpLogs.azureBlobStorage.retentionInDays = 0
            $logSetting.Properties.httpLogs.azureBlobStorage.enabled = $true
            $logSetting.Properties.httpLogs.fileSystem.enabled = $false
            # update the log setting
            $setResourceArgs = $getResourceArgs.Clone()
            $result = Set-AzureRmResource -Properties $logSetting.Properties @setResourceArgs -Force
        }
    
    0 讨论(0)
提交回复
热议问题