【问题标题】:Azure Functions (v2): different logging behavior per environmentAzure Functions (v2):每个环境的不同日志记录行为
【发布时间】:2019-08-01 21:34:29
【问题描述】:

我有一个具有多种功能的函数应用程序(v2、.NET Core)。此 Functions 应用程序部署到不同的环境(= 不同的订阅)。出于开发目的,我大量使用(ILogger)日志,但我想在部署到开发以外的其他环境时关闭日志。 Function 应用通过 Azure DevOps 管道部署。

您建议采用哪种方法来实现这一目标(在代码中、通过 appsettings、通过 host.json...)?

谢谢

【问题讨论】:

    标签: logging deployment configuration azure-functions


    【解决方案1】:

    我还没有找到解决方案,例如可以通过例如设置的变量应用程序设置,我不想重构代码以使用某种调试标志(尤其是host.json 中还可以有其他特定于环境的设置)。

    我现在做的是在管道中使用PowerShell任务来根据环境设置host.json的内容。 IE。我为存储库中的每个环境都有一个host.json 文件,并且基于相应的环境,主要的host.json 设置为特定于环境的host.json 的内容。

    PowerShell 任务如下所示:

    ###########################
    # Get environment variables
    $releaseEnvironment = $env:RELEASE_ENVIRONMENTNAME
    $currentWorkingDirectory = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
    
    ###########################
    # Get config data
    $configFileName = "$($releaseEnvironment)_host.json"
    $configFilePath = "$currentWorkingDirectory$projectPath\Deployment\Host\$configFileName"
    $configFileContent = Get-Content -Raw -Path $configFilePath | ConvertFrom-Json
    Write-Host "Working with '$configFilePath'..."
    
    ###########################
    # Update host.json
    $pathToHostJsonInUse = "$currentWorkingDirectory$projectPath\host.json"
    $configFileContent | ConvertTo-Json -Depth 100 | Set-Content -Path $pathToHostJsonInUse
    Write-Host "Updated '$pathToHostJsonInUse'..."
    

    在这种情况下有用的资源是:

    https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring#configure-categories-and-log-levels

    https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 2021-09-27
      相关资源
      最近更新 更多