Azure 函数详细跟踪日志记录到 Application Insights

Azure function verbose trace logging to Application Insights

我有一个连接到 App Insights 实例的 Azure 函数。函数应用发出日志消息,我可以在 Azure 门户的日志流中看到这些消息,并作为 App Insights 跟踪。

我通过向 host.json (https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json) 添加 "tracing" 元素将控制台日志级别提高到详细,因此详细级别的消息显示在日志流中(在Azure 门户和 Kudu 中的功能页面),但我无法在 App Insights 中显示详细级别的跟踪。

有谁知道如何让 App Insights 显示来自 Azure 函数的详细级别跟踪?有可能吗? (信息痕迹及以上在 App Insights 中显示得很好)

您可以在 Functions 中对 App Insights 的日志级别进行很多控制,但您不会为此使用 tracing 元素。我们正在努力将文档集中在一个统一的位置,但这里有一些链接可以提供帮助:

对于您的具体示例,您可以在 host.json 中打开所有 Debug 日志(与 TraceWriter 中的 Verbose 匹配):

{
  "logger": {
    "categoryFilter": {
      "defaultLevel": "Debug"     
    }
  }
}

如果您只想查看来自您的函数本身的详细日志(即您不希望出现主机的详细日志),您可以使用此限制——'for logs with the "Function" category (which is the category that function logs use), show me everything with Debug or higher log level':

{
  "logger": {
    "categoryFilter": {
      "categoryLevels": {
        "Function": "Debug"
      }
    }
  }
}