'Azure Blob Trigger Function triggering only once when file is updated with NLog

I am using NLog to log the messages in azure blob storage with blob name as dd-mm-yyyy.log. For each and every message which I inserted into "dd-mm-yyyy.log" file, I want to call/trigger the azure blob trigger function.

For Example, if I insert 3 message in one request one after the other, then azure blob trigger function should trigger 3 times. Curranty it is trigging only 1 time.

But if I insert 3 message with 1 min difference (i.e. 1 message at 1 min), then the azure blob trigger function triggering 3 times.

Below is the Nlog code:

try
{
    //Some logic
}
catch (Exception ex)
{
    LoggingHelper.Fatal($"Exception : {Convert.ToString(ex)}");
    LoggingHelper.Fatal($"InnerException : {Convert.ToString(ex.InnerException)}");
    LoggingHelper.Fatal($"Exception StackTrace: {ex.StackTrace}");
}

Azure Blob trigger code:

[FunctionName("Function1")]
public static async Task Run([BlobTrigger("poccontainer/{name}", Connection = "")] Stream myBlob, string name, 
    ILogger log, ExecutionContext context, BlobProperties Properties)
{
    log.LogInformation($"Blob Name:{name}");
    //Logic to process the file data
}

I want to trigger the azure blob trigger function every time when I insert a message into dd-mm-yyyy.log.

Solution which I tried but no use: I have added below code in the host.json file but no use.

{
  "version": "2.0",
  "extensions": {
    "queues": {
      "batchSize": 1
    }
  }
}

Any help is really appreciated.



Solution 1:[1]

I suggest not using the Azure Blob Trigger for the Function at all. The blob trigger relies on a polling mechanism so timing might be the issue in your case. From the docs:

[...] There's no guarantee that all events are captured. Under some conditions, logs may be missed.

If you require faster or more reliable blob processing, consider creating a queue message when you create the blob. Then use a queue trigger instead of a blob trigger to process the blob. Another option is to use Event Grid; see the tutorial Automate resizing uploaded images using Event Grid.

I would definitely check the Event Grid Trigger in your case. Or, if order is important, the queue based trigger.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Bons