azure - 如何从 C# 或 Microsoft.Azure.Management 删除应用服务 -> Web 应用 -> 日志文件
问题描述
目前通过 Kudo / Azure CLI / FTP 登录并手动删除。
我们有一个现有的 dev-ops 代码库,它使用Microsoft.Azure.Management
. 寻找任何方法来删除文件,特别是/LogFiles/*.log
在使用 C# 模糊的 x 之前。
似乎可以枚举 WebApps 并获取 FTP 凭据并使用FtpWebRequest
,但想知道是否有更直接的方法。
在这里没有看到任何方法 -> Web Apps:
解决方案
恐怕没有直接的方法。但是,您可以调用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)
您还可以参考此线程中的另一个示例。
您还可以创建一个azure web 作业并上传一个 powershell 脚本来删除旧的日志文件。请在此处查看详细步骤。
推荐阅读
- ruby-on-rails - Ruby on Rails:如何按当前用户显示所有产品
- php - 构建一个 WordPress 查询以仅显示当前选定标签内的帖子
- c# - 具有拖放操作的 DataGridView ArgumentOutOfRangeException
- postgresql-12 - Linux处于救援模式,如何备份我的postgres数据库?
- azure-application-insights - Application Insights 聚合事件发生的总和
- python - 我不知道如何解决这个问题(discord.py)
- r - cmprsk 包中的微分线,用于竞争风险生存曲线
- javascript - 未处理的拒绝(TypeError):使用 React 创建天气应用程序时无法读取未定义的属性“过滤器”
- python - 以编程方式将 Salesforce 报告下载为 csv
- .net-5 - 使用 Oakton 检查我的 Net5 核心应用程序的 Lamar 配置并获得空引用,我该如何解决这个问题?