2
votes

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

3 Answers

2
votes

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

1
votes

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
votes

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
    }