如何从 Azure Function App 日志中删除 Azure.Storage.Blobs 日志记录?

问题描述 投票:0回答:2

我已开始在我的函数应用程序中使用 Azure.Storage.Blobs nuget。 目前它造成的唯一问题是它记录了很多我不需要看到的不必要的东西。主要是请求和响应消息,它们现在占据了我的大量应用程序见解。

有没有办法在不接触任何其他日志的情况下删除它们?我认为您应该能够从 host.json 执行某些操作,但到目前为止,我还没有解决这个问题。

我得到的示例日志:

请求 [f42fdb4b-8d26-418d-ae67-1d4e79bdabd6] GET x-ms-版本:2021-08-06 接受:application/xml x-ms-client-request-id:x-ms-return-client-request -id:true 用户代理:azsdk-net-Storage.Blobs/12.13.0,(.NET 6.0.8; Microsoft Windows 10.0.14393) x-ms-date:2022 年 9 月 29 日星期四 19:07:43 GMT授权:已编辑客户端程序集:Azure.Storage.Blobs

响应 [f42fdb4b-8d26-418d-ae67-1d4e79bdabd6] 200 OK(00.0s)接受范围:字节 ETag:“”服务器:Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0 x-ms-request-id : x-ms-client-request-id: x-ms-version:2021-08-06 x-ms-version-id:已编辑 x-ms-is-current-version:已编辑 x-ms-creation-time :2022 年 9 月 29 日星期四 19:07:39 GMT x-ms-lease-status:已解锁 x-ms-lease-state:可用 x-ms-blob-type:BlockBlob x-ms-server-encrypted:true 日期: 2022 年 9 月 29 日星期四 19:07:43 GMT 内容长度:222058 内容类型:application/pdf 内容 MD5:最后修改时间:2022 年 9 月 29 日星期四 19:07:39 GMT 内容处置:

在处理 blob 的函数中,将会有很多这样的请求/响应日志。我倾向于用 try-catch 包装我的操作并记录可能的错误,因此编写这些完全没有意义。

azure azure-functions azure-blob-storage azure-application-insights
2个回答
0
投票

当我使用 QueueTrigger 时,我遇到了同样的问题,我的解决方法是从单例和依赖注入中删除我的 TelemetryClient。它还设法删除所有内置日志。代码示例。

public class Function1
{
        private readonly TelemetryClient _telemetryClient;

        public Function1() 
        {
            _telemetryClient = TelemetryClientHelper.GetInstance();
        }
}

public static class TelemetryClientHelper
    {
        private static TelemetryClient _telemetryClient;
        public static TelemetryClient GetInstance()
        {
            if(_telemetryClient == null)
            {
                var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
                telemetryConfiguration.ConnectionString = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING");
                _telemetryClient = new TelemetryClient(telemetryConfiguration);
            }
            
            return _telemetryClient;
        }
    }

0
投票

不久前已经找到了解决方案,但忘记发布答案。 我设法使用 Azure Function 项目中包含的 host.json 文件删除不必要的日志记录。添加 Azure.Core 作为 Error 就成功了。

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false
      },
      "enableDependencyTracking": true
    },
    "logLevel": {
      "default": "Information",
      "Azure.Core": "Error",
      "System.Net.Http.HttpClient": "Information",
      "Azure.Messaging.ServiceBus": "Error"
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.