Azure PowerShell: Enable Application Diagnostics and Site Diagnostics

假装没事ソ 提交于 2019-12-01 08:17:34

问题


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

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

Site Diagnostics to Blob Storage:

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?


回答1:


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




回答2:


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:


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
    }


来源:https://stackoverflow.com/questions/25996437/azure-powershell-enable-application-diagnostics-and-site-diagnostics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!