使用 Azure Log Analytics 在 Azure Function v3 中进行结构化日志记录

Structured logging in an Azure Function v3 with Azure Log Analytics

我正在尝试通过像这样登录我的 Azure 函数来使用结构化日志记录:

log.LogError("Failed to get object. ({customerId}, {objectId}, {errorMessage})", request.CustomerId,
                    request.ObjectId, errorMessage);

我的 Azure 函数已通过诊断设置插入到 Log Analytics 工作区。

有没有办法从消息中提取 customerId、objectId 和 errorMessage?

我想创建一个显示每个客户 ID 的错误数量的仪表板。

我试过“提取字段”功能但无济于事。我是否需要使用 Application Insights 和自定义维度?

您几乎已经走上了正确的道路。使用上面共享的示例日志语句,如果启用 built-in App Insights Integration. That's the exact reason, Loging in .net core is built this way for templating. You can also find details in Azure Function structured logging,您应该已经在 Application Insights 日志的 customDimentions 中看到 customerId、objectId、errorMessage。

但是您提到您正在通过诊断设置使用 Log Analytics 工作区,我认为该设置尚不支持结构化日志记录(目前处于预览阶段,因此将来可能会更改)。

因此,Application Insights 将是您的不二之选。除了 App Insights 的内置查询窗格之外,您还可以从 Log Analytics 查询应用程序见解。