BladeZ
BladeZ

Reputation: 217

How to remove Azure.Storage.Blobs logging from Azure Function App logs?

I have started using Azure.Storage.Blobs nuget in my Function Apps. Only problem it causes at the moment is that it logs a lot of unnecessary stuff that I don't need to see. Mainly Request and Response messages that fill a large amount of my application insights now.

Is there a way to remove those without touching any other logs? I would assume you should be able to do something from host.json, but so far nothing has worked for me to tackle this problem.

Example logs that I get:

Request [f42fdb4b-8d26-418d-ae67-1d4e79bdabd6] GET <resource_address> x-ms-version:2021-08-06 Accept:application/xml x-ms-client-request-id: x-ms-return-client-request-id:true User-Agent:azsdk-net-Storage.Blobs/12.13.0,(.NET 6.0.8; Microsoft Windows 10.0.14393) x-ms-date:Thu, 29 Sep 2022 19:07:43 GMT Authorization:REDACTED client assembly: Azure.Storage.Blobs

Response [f42fdb4b-8d26-418d-ae67-1d4e79bdabd6] 200 OK (00.0s) Accept-Ranges:bytes ETag:"" Server:Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0 x-ms-request-id: x-ms-client-request-id:<request_id> x-ms-version:2021-08-06 x-ms-version-id:REDACTED x-ms-is-current-version:REDACTED x-ms-creation-time:Thu, 29 Sep 2022 19:07:39 GMT x-ms-lease-status:unlocked x-ms-lease-state:available x-ms-blob-type:BlockBlob x-ms-server-encrypted:true Date:Thu, 29 Sep 2022 19:07:43 GMT Content-Length:222058 Content-Type:application/pdf Content-MD5: Last-Modified:Thu, 29 Sep 2022 19:07:39 GMT Content-Disposition:

In functions where blobs are handled there will be A LOT of request/response logs like these. I tend to wrap my operations with try-catch and log possible errors, so these are completely pointless to write.

Upvotes: 9

Views: 2074

Answers (2)

BladeZ
BladeZ

Reputation: 217

Found the solution to this a while back already, but forgot to post answer. I managed to remove unnecessary loggings using host.json file included in Azure Function projects. Adding Azure.Core as Error did the trick.

{
  "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"
    }
  }
}

Upvotes: 5

user20238831
user20238831

Reputation: 11

I had the same problem when I used QueueTrigger, and my fix is to remove my TelemetryClient from singleton and in dependency injection. It also manages to remove all built-in logs. Example of the code.

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;
        }
    }

Upvotes: 1

Related Questions