skip to Main Content

Just upgraded an azure function from v3 to v4 and dotnet6. Noticed that the runtime bindings need to be updated too.

I’#ve just been testing it, and noticed there’s a lot of verbose logging coming from the Table binding along with my own logging. How can I exclude this? Should I be looking to exclude it? It makes it hard to see the wood from the trees when looking at a live log

[FunctionName("Function2")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            [Table("Keys", Connection = "TableStorage")] TableClient keysTable,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
         
            if (keysTable != null)
            {
                try
                {
                    var item2 = keysTable.GetEntity<TableEntity>("jon", "test");  
                }
                catch (Exception)
                {
                    log.LogError("key not present");
                }
            }

            log.LogInformation("C# HTTP trigger function completed.");
            return new OkObjectResult(new { });
        }

log output

2022-12-28T12:40:14Z   [Information]   Request [6b093468-5e75-4e8c-b358-e47f0dffc632] POST https://xxx.table.core.windows.net/Tables?$format=REDACTED
x-ms-version:REDACTED
DataServiceVersion:REDACTED
Prefer:REDACTED
Accept:application/json; odata=minimalmetadata
x-ms-client-request-id:6b093468-5e75-4e8c-b358-e47f0dffc632
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Data.Tables/12.7.1,(.NET 6.0.11; Microsoft Windows 10.0.14393)
x-ms-date:REDACTED
Authorization:REDACTED
Content-Type:application/json; odata=nometadata
client assembly: Azure.Data.Tables
2022-12-28T12:40:14Z   [Information]   Response [6b093468-5e75-4e8c-b358-e47f0dffc632] 409 Conflict (00.0s)
Cache-Control:no-cache
Transfer-Encoding:chunked
Server:Windows-Azure-Table/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id:e63cd248-2002-0051-25b9-1ae043000000
x-ms-client-request-id:6b093468-5e75-4e8c-b358-e47f0dffc632
x-ms-version:REDACTED
X-Content-Type-Options:REDACTED
Preference-Applied:REDACTED
Date:Wed, 28 Dec 2022 12:40:13 GMT
Content-Type:application/json; odata=minimalmetadata; streaming=true; charset=utf-8
2022-12-28T12:40:14Z   [Information]   Executing 'Function2' (Reason='This function was programmatically called via the host APIs.', Id=3598edde-1658-414b-9cc4-481bb6f7810e)
2022-12-28T12:40:14Z   [Information]   C# HTTP trigger function processed a request.,

I’d have thought only my logging would be appearing.

I’ve read through this and found this nugget of information

https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring#disable-built-in-logging

Dependencies
Starting with version 2.x of Functions, Application Insights automatically collects data on dependencies for bindings that use certain client SDKs. Application Insights distributed tracing and dependency tracking aren’t currently supported for C# apps running in an isolated worker process. Application Insights collects data on the following dependencies:

Azure Cosmos DB
Azure Event Hubs
Azure Service Bus
Azure Storage services (Blob, Queue, and Table)

Doesnt say how to disable it

Host.json file

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

2

Answers


  1. The host.json code you have given will log/capture the live data coming during the request and response.
    As @AnandSowmithiran said, there is an attribute loglevel that defines the collection of logs you require while you run the Function App.

    You have to add the logLevel attribute to host.json before publishing the function project and that attribute sets the values such as levels of logs which are Information, Error, Trace and there are two categories of log levels which are function logs and host logs.

    Refer to the SO Q&A 70683888 given by @HariKrishna, regarding the Azure Functions Log Level Setting Information and also the optimization of heavy logs for minimizing the Monitor pricing.

    Login or Signup to reply.
  2. Updating the host.json file to include only the Error logs from these categories worked for me.

    {
      "version": "2.0",
      "logging": {
        "logLevel": {
          "default": "Information",
          "Azure.Core": "Error",
          "Azure.Messaging.ServiceBus": "Error"
          //others categories you have noise
        }
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search