gpt4 book ai didi

Azure Functions 日志始终为空

转载 作者:行者123 更新时间:2023-12-02 23:44:16 24 4
gpt4 key购买 nike

我在 Visual Studio 2017 中创建了一个面向 .NET Core 的 Azure Functions 应用。我使用的是由 Azure Functions 项目模板自动生成的简单的 Hello, {name} 示例。

public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
log.LogDebug("A debug message");

string name = req.Query["name"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;

return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}

当我将其部署到 Azure,运行该函数,然后在 Kudu 中查看调用详细信息时,日志始终具有值 null

Kudu Invocation Details

点击“切换输出”按钮不会加载日志。它无限期地卡在“正在加载”状态。

如何查看 Azure 函数的日志输出?

最佳答案

对于运行时 2.x 中的 v2 函数,doc解释

To improve monitoring, the WebJobs dashboard in the portal, which used the AzureWebJobsDashboard setting is replaced with Azure Application Insights, which uses the APPINSIGHTS_INSTRUMENTATIONKEY setting.

就像您所看到的那样,使用 AzureWebJobsDashboard 设置,日志参数为 null,并且那里没有日志。恐怕强制执行了替换,并且仪表板已被弃用

创建 Application Insight 并添加其 instrumentationkey 后在应用程序设置中,我们可以看到监视器 View 类似于仪表板。

enter image description here

如果我们不喜欢它,那么 kudu( https://<functionAppName>.scm.azurewebsites.net/DebugConsole ) 中的日志已准备就绪 ( D:\home\LogFiles\Application\Functions\function\<functoinName> )。

关于Azure Functions 日志始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54974493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com