0

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"
            }
        }
    }
}
Stefan
  • 249
  • 1
  • 10
  • post the azure function code + startup / program.cs (for NET 5 isolated) and host.json – Thiago Custodio Aug 31 '21 at 20:16
  • @ThiagoCustodio I added the code for the .NET 5 function. This is what I got from following the tutorial on the Microsoft Docs. – Stefan Aug 31 '21 at 20:25
  • 1
    things look ok to me, just make sure the local.settings.json have a valid entry for something_STORAGE: https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local#local-settings-file – Thiago Custodio Aug 31 '21 at 20:31
  • @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 Sep 01 '21 at 03:52
  • @Shyju I don't get any notifications, and the connection string is configured. – Stefan Sep 01 '21 at 18:12
  • Make sure you configure it (in azure portal) as an entry under AppSettings, not connection strings. Your code looks fine and should work. – Shyju Sep 01 '21 at 18:59
  • 1
    @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 Sep 02 '21 at 14:38

1 Answers1

0

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

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12