我正在配置Diagnostics& Azure网站的IIS日志。 Azure管理门户显示将应用程序诊断存储到Azure表存储的选项:
然后弹出一个关于点击“管理表存储”的对话框,以提供Azure表详细信息:
Blob存储的站点诊断:
我正在搜索Azure Cmdlet,以便在部署时使用PowerShell启用它们。
这是我能找到的Cmdlet,但它没有提供表格详细信息的任何选项:
Enable-AzureWebsiteApplicationDiagnostic
C:\PS>Enable-AzureWebsiteApplicationDiagnostic -Name MyWebsite -Storage -LogLevel Information -StorageAccountName myaccount
还有其他方法吗?
答案 0 :(得分: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
答案 1 :(得分:1)
启用表诊断后,尝试将此SAS_setting设置为表格的SAS URL:
DIAGNOSTICS_AZURETABLESASURL
示例:
$site = get-azurewebsite mysite
$site.AppSettings.Add("DIAGNOSTICS_AZURETABLESASURL", "<YOUR TABLE SAS URL>")
set-azurewebsite $site.Name -AppSettings $site.AppSettings
您可以在此处找到有关SAS网址的更多信息:http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx
您不能只设置表名,因为为了安全起见,它需要更多信息才能完全访问表以便写入数据。
答案 2 :(得分:0)
现在Enable-AzureWebsiteApplicationDiagnostic
不起作用。参见Enable-AzureWebsiteApplicationDiagnostic: specify storage account name?
使用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
}