Search code examples
c#azureazure-storageilogger

Stop logging from TableClient


I have a function app that uses a table client.

svc.AddAzureClients(bldr =>
{
    var serviceUrl = tableStorageSection["ServiceUrl"] ?? throw new ArgumentNullException("Missing value for Values:TableStorage:ServiceUrl");
    bldr.UseCredential(new DefaultAzureCredential())
        .AddTableServiceClient(new Uri(serviceUrl));
});

When I run the function locally, this client spits out a bunch of logs. enter image description here I don't want to see those, I only want the logs from my own code. However I do not seem to be able to disable it. Here's what I have in my host.json file.

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "LogLevel": {
      "Default": "Information",
      "MyApi": "Debug",
      "Azure": "None",
      "System": "None",
      "Microsoft":  "None"
    },
    "Console": {
      "IncludeScopes": false,
      "FormatterName": "MyFormatter"
    },
    "EventSource": {
      "LogLevel": {
        "Default": "None"
      }
    }
  }
}

I even created a custom formatter that outputs a logentry's category to see if the logs come from a special category, but it seems my formatter is not being used by this logger. Am I missing something here?


Solution

  • I was able to tune the logging by calling the ConfigureLogging method on the HostBuilder

    hostbldr.ConfigureLogging((ctx, configure) =>
    {
        configure.Services.Configure<LoggerFilterOptions>(options =>
        {
            options.Rules.Add(new LoggerFilterRule("Microsoft.Azure.Functions.Worker.Logging.WorkerLoggerProvider", "Azure", LogLevel.Warning, (a, b, l) => true));
        });
    });