2

我正在为 Azure 网站配置诊断和 IIS 日志。Azure 管理门户显示将应用程序诊断存储到 Azure 表存储的选项:

应用程序诊断

并弹出一个对话框,单击“管理表存储”以提供 Azure 表详细信息:

在此处输入图像描述

Blob 存储的站点诊断:

现场诊断

我正在搜索 Azure Cmdlet 以在部署时使用 PowerShell 启用这些功能。

这是我可以找到的 Cmdlet,但它没有提供表格详细信息的任何选项:

启用-AzureWebsiteApplicationDiagnostic

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

有没有其他方法可以做到这一点?

4

3 回答 3

2

这显然已在 Azure PowerShell cmdlet 的最新版本(截至 2016 年 3 月 21 日)中得到修复。您现在可以指定表/容器名称,例如

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

于 2016-03-21T16:11:08.060 回答
1

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.

于 2014-09-23T14:37:29.243 回答
0

现在Enable-AzureWebsiteApplicationDiagnostic不起作用。请参阅Enable-AzureWebsiteApplicationDiagnostic:指定存储帐户名称?

这是使用过的(多亏了这一点:Is there a way to enable application logging to blob for azure app service using PowerShell or ARM template?

还可以发现在那里使用https://resources.azure.com和 Powershell 选项卡非常有用。

    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
    }
于 2018-07-31T16:23:07.870 回答