现在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
}