How to add configuration values in AppSettings.json in Azure functions. Is there any structure for it?

后端 未结 7 2004
别那么骄傲
别那么骄傲 2021-02-12 18:51

What is the standard structure to add keys to appsettings.json? Also, how to read those values in our run.csx? Normally in app.config, we had Con

7条回答
  •  佛祖请我去吃肉
    2021-02-12 19:24

    To load the environment or appsettings value you need to use the

    System.Environment.GetEnvironmentVariable property

    public static void Run(TimerInfo myTimer, TraceWriter log)
    {
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
        log.Info(GetEnvironmentVariable("AzureWebJobsStorage"));
        log.Info(GetEnvironmentVariable("WEBSITE_SITE_NAME"));
    }
    
    public static string GetEnvironmentVariable(string name)
    {
        return name + ": " + 
            System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
    }
    

    Manage app settings variables - https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings

提交回复
热议问题