【问题标题】:How to Delete App Service -> Web App -> Log Files from C# OR Microsoft.Azure.Management如何从 C# 或 Microsoft.Azure.Management 删除应用服务 -> Web 应用 -> 日志文件
【发布时间】:2019-11-04 16:44:25
【问题描述】:

目前通过 Kudo / Azure CLI / FTP 登录并手动删除。

我们有一个使用 Microsoft.Azure.Management 的现有开发操作代码库。寻找删除文件的任何方法,特别是 /LogFiles/*.log,其中使用 C# 模糊地比 x 更早。

似乎可以枚举 WebApps 并获取 FTP 凭据并使用FtpWebRequest,但想知道是否有更直接的方法。

这里没有看到任何方法-> Web Apps:

【问题讨论】:

    标签: azure azure-devops azure-web-app-service


    【解决方案1】:

    恐怕没有直接的方法。但是,您可以致电Kudu Api 删除日志文件。下面是一个powershell脚本示例:

    $ResGroupName = ""
    $WebAppName = ""
    $LogFolder = ""
    $DaysToKeepLogsAround=""
    
    # Get publishing profile for web application
    
    $WebApp = Get-AzWebApp -Name $WebAppName -ResourceGroupName $ResGroupName
    [xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp
    
    # Create Base64 authorization header
    
    $username = $publishingProfile.publishData.publishProfile[0].userName
    $password = $publishingProfile.publishData.publishProfile[0].userPWD
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
    
    $apiBaseUrl = "https://$($WebApp.Name).scm.azurewebsites.net/api/command"
    
    # delete log files
    
     $apiCommand = @{
            command = 'powershell.exe -command "Get-ChildItem -Path $LogFolder -Recurse -File | Where LastWriteTime  -lt  (Get-Date).AddDays(-$DaysToKeepLogsAround) | Remove-Item -Force"'
            dir=$LogFolder
        }
    
    Invoke-RestMethod -Uri $apiBaseUrl -Headers @{"Authorization"="Basic $base64AuthInfo";"If-Match"="*"} -Method POST -ContentType "application/json" -Body (ConvertTo-Json $apiCommand)
    

    您也可以参考此thread 中的另一个示例。

    您还可以创建 azure web 作业 并上传 powershell 脚本以删除旧的日志文件。详细步骤请查看here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多