Azure V3函数登录另一个类库

标签 azure logging azure-functions

我有一个 Azure 函数,我可以成功地从应用程序函数写入日志,但我想在另一个类库中使用记录器。 我已经在 DI 中完成并添加了必要的代码,但它没有记录任何内容。

Azure函数代码是

enter image description here

业务数据服务代码为

enter image description here

启动类代码是。 AddLoggin() 是可选的,但无论有没有它都不起作用。

enter image description here

host.json 文件

enter image description here

我可以看到从函数应用程序 (MaterDataTimerTrigger) 写入的日志,但看不到从 MasterDataBusinessService 写入的任何内容

更新:我根据评论更改了 host.json 文件,它起作用了。

{
"version": "2.0",
"logging": {
"logLevel": {
  "default": "Information"
}
}
}

最佳答案

来自this Microsoft documentation --- 所有函数和遥测类别的默认值都设置为警告(包括 Microsoft 和 Worker 类别),因此默认情况下,会收集运行时和自定义日志记录生成的所有错误和警告。

因此,要获得信息级别,您应该在 host.json 文件中定义 logLevel。

"logging": {
    "logLevel": {
      "default": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }

此外,我建议将 samplingSettings 设置为 false,以便所有日志都记录在应用程序洞察中,而不是采样日志。

关于Azure V3函数登录另一个类库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71643632/

相关文章:

python - 如何在 python Flask-tornado 应用程序中管理多个记录器

azure - 来自带有 .net core 的 Azure function 2.0 的引用文件

azure - 如何在 Linux RHEL 中安装特定版本的 Azure CLI

postgresql - 将 Power BI 服务连接到 Azure 上的 PostgreSQL 数据库

sql-server - Azure SQL 数据库发布问题

azure - 有什么方法可以在 Azure 网站中进行 "sticky folders"(或类似的)w/staged 部署?

php - Cakephp 3 无法从插件加载类

c# - 在Visual Studio中运行.net应用程序时,我们可以直接登录Cloudwatch吗

node.js - Azure函数: IoTHub as Input and Output

azure - Azure Function 如何针对 SignalR 进行身份验证?