简体   繁体   English

Azure Function v4 - 如何关闭主机日志记录

[英]Azure Function v4 - How Turn Off Host Logging

I have a C# Azure Function app that gets deployed via DevOps build and release pipeline.我有一个通过 DevOps 构建和发布管道部署的 C# Azure Function 应用程序。

It was running on the v3 Functions runtime.它在 v3 Functions 运行时上运行。 I've recently updated the project file and bicep template of the function app so that it runs on v4.我最近更新了 function 应用程序的项目文件和二头肌模板,以便它在 v4 上运行。

The app is configured to log to Azure Sql through Serilog.该应用程序配置为通过 Serilog 记录到 Azure Sql。 since the update I've noticed many thousands of additional log entries from the Azure Functions Host自更新以来,我注意到来自 Azure Functions Host 的数千个额外日志条目

The logging section of my appsettings.json file is shown below.我的 appsettings.json 文件的日志记录部分如下所示。 My understanding is these would be used where equivalent values are available to the Function App as environment variables - through the configuration settings section of the function app?我的理解是这些将用于 Function 应用程序作为环境变量可用的等效值 - 通过 function 应用程序的配置设置部分?

"Logging": {
"LogLevel": {
  "Default": "Error"
},
"ApplicationInsights": {
  "LogLevel": {
    "Default": "Information"
  }
}
}

I tried following the answer to this post in order to suppress the logging by adding the following entries in the function app's application settings:我尝试按照这篇文章的答案,通过在 function 应用程序设置中添加以下条目来抑制日志记录:

"name": "AzureFunctionsJobHost__Logging__LogLevel__Microsoft",
"value": "Error"

"name": "AzureFunctionsJobHost__Logging__LogLevel__Azure",
"value": "Error"

I restarted the function app but noticed no difference in the logs.我重新启动了 function 应用程序,但发现日志没有区别。 Here's an example of one of the unwanted log records (all logged with a with a level of "Information"):下面是一个不需要的日志记录的示例(所有记录都以“信息”级别记录):

<properties>
<property key='requestId'>bcc9a52c-fb8b-4a89-bb1c-9ed08eb305c4</property>
<property key='status'>200</property>
<property key='reasonPhrase'>OK</property>
<property key='seconds'>0.0048284</property>
<property key='EventSourceEvent'>Response [bcc9a52c-fb8b-4a89-bb1c-9ed08eb305c4] 200 OK (00.0s)</property>
<property key='EventId'>
    <structure type=''>
        <property key='Id'>5</property>
        <property key='Name'>Response</property>
    </structure>
</property>
<property key='SourceContext'>Azure.Core</property>

Sorry to anyone that looked at this - I was being an idiot!抱歉看到这个的人 - 我是个白痴!

Another project had recently been added to the solution and I was looking at config for the wrong project.最近将另一个项目添加到解决方案中,我正在查看错误项目的配置。

For anyone struggling with a similar problem, I recommend trying serilog config that can be adjusted at runtime rather than having to redeploy C# containing your Serilog LoggerConfiguration object.对于遇到类似问题的任何人,我建议尝试可以在运行时调整的 serilog 配置,而不必重新部署包含 Serilog LoggerConfiguration object 的 C#。 This github link explains how这个github 链接解释了如何

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM