0
votes

I'm trying to setup an Azure Function that is triggered by a new message in an Azure Storage Queue. I have the code setup to send messages to the Queue as follows:

QueueClient queue = new(connectionString, queueName);
await queue.SendMessageAsync(message);

This part works fine. When I pass in the connectionString, queueName, and message, I can see the message sitting in the Queue on the portal.

This is the part I'm having trouble understanding. I setup an Azure Function using the Azure Storage Queue template, and the queue it's referencing is the same as queueName. However, when a message gets added to the queue, the Azure Function doesn't log anything. From what I understood, the Azure Function should be triggered by a message being added to the queue it's pointed it, and it should log the message. I tried both the .NET Core 3.1 In Process and .NET 5 isolated process. I'm not sure what I'm missing here, or if I'm misunderstanding something. This is the code for the Azure Function (.NET 5).

[Function("QueueTrigger1")]
public static void Run([QueueTrigger("myqueue-items", Connection = "something_STORAGE")] string myQueueItem, FunctionContext context)
{
    var logger = context.GetLogger("QueueTrigger1");
    logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}

This is the program.cs

public static void Main()
{
    var host = new HostBuilder()
        .ConfigureFunctionsWorkerDefaults()
        .Build();

    host.Run();
}

This is the host.json

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}
1
post the azure function code + startup / program.cs (for NET 5 isolated) and host.json - Thiago Custodio
@ThiagoCustodio I added the code for the .NET 5 function. This is what I got from following the tutorial on the Microsoft Docs. - Stefan
things look ok to me, just make sure the local.settings.json have a valid entry for something_STORAGE: docs.microsoft.com/en-us/azure/azure-functions/… - Thiago Custodio
@Stefan Do you see any "notifications" for your functions app in azure portal ? Missing/incorrect connection strings are usually reported there. Do you have a Configuration AppSettings called something_STORAGE which has the connection string value ? - Shyju
@Shyju This was the problem, I didn't realize that the local.settings.json wasn't being used in Azure. I changed the Connection value to one that was in the Azure Portal and it worked. - Stefan

1 Answers

0
votes

FileLoggingMode is used to generate the logs in azure portal or in a local Environment. The different modes in “fileLoggingMode” are

“debugOnly”: This level will generate logs when the function app is running on Azure Portal. This is the default mode.

“always”: This mode is used to generate logs in local environment as well as when running on Azure Portal. This code reference can be helpful to understand it better.

“never”: This mode does not generate any logs.

You need replace the host.json with below code to configure logging information of our function.

 {
   "version":"2.0",
   "logging":{
      "fileLoggingMode":"debugOnly",
      "logLevel":{
         "Function.MyFunction":"Error",
         "default":"Information",
          "Host": "Error", 
          "Host.Aggregator": "Information"
      },
      "applicationInsights":{
         "samplingSettings":{
            "isEnabled":true,
            "excludedTypes":"Request"
         }
      }
   }
}

Reference link to configure log level for a function app For more information about azure function logging you can refer below SO thread