Azure PowerShell: Enable Application Diagnostics a

2019-02-19 08:25发布

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

Application Diagnostics

And pops up a dialog on clicking 'manage table storage' to provide Azure Table details:

enter image description here

Site Diagnostics to Blob Storage:

Site Diagnostics

I am searching for Azure Cmdlet to enable these using PowerShell at deployment time.

Here is the Cmdlet i could find but it doesnt have any option to provide table details:

Enable-AzureWebsiteApplicationDiagnostic

C:\PS>Enable-AzureWebsiteApplicationDiagnostic -Name MyWebsite -Storage -LogLevel Information -StorageAccountName myaccount

Is there any otherway to do this?

3条回答
你好瞎i
2楼-- · 2019-02-19 08: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.

查看更多
男人必须洒脱
3楼-- · 2019-02-19 09:12

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

查看更多
乱世女痞
4楼-- · 2019-02-19 09:12

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
    }
查看更多
登录 后发表回答