0

Have created a multiproject solution in C# .NET6 in which there is a Function project. Function project contains a timer triggered function:

  [FunctionName("Function1")]
  public async Task Run([TimerTrigger("0 0/1 * * * *")]TimerInfo myTimer, ILogger log)
  {
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

Am using Visual studio 2022 so have right clicked the function project in my solution and choosen publish. The publishing works and the app is uploaded to Azure and creates a new Function in Azure portal that is up and running.

In Application Insight on Azure portal I can see the following message in Transaction Search: Host Status: { "id": "functionappjohantest", "state": "Running", "version": "4.30.0.22097",.................. However the timer trigger that is set to once a minute is never triggered as there is no new input in Application Insight.

What is wrong here?

UPDATE - After lots of trying and mixed results I deleted my whole resource group and created a new one, also created new function solutions (two .NET6, one isolated and one not, one .NET8 isolated). Created new application insight group etc that came with publishing functions to Azure.

Azure

Without making any own changes there is a difference with profile settings between .NET8 and .NET6, both seems to work fine though. enter image description here

I see both the isolated and not isolated functions running with invocation trace in each function but when looking in application insight transaction search I can see all functions executing: enter image description here But can't see the log of the isolated processes who use this type of log setup in visual studio: enter image description here

So in conclusion, I have no idea what was wrong before and still don't understand why logging isn't showing up in transaction search for the application insight group but besides that it seems work.

2
  • Your cron expression is incorrect. If you want it to execute every minute, you want 0 * * * * * arminreiter.com/2017/02/… Commented Mar 14, 2024 at 0:27
  • Did you able to run the function as you expected? can you check the runtime stack and .net version of which you created functionapp? Commented Mar 14, 2024 at 5:45

1 Answer 1

1

Thanks, Adam Vincent for the insights.

  • Timer triggers require the function app to be "warmed up" to execute on schedule, and enabling "Always On" ensures that your function app remains active. refer this SO LINK
  • I have tried the same in my environment with the below code and it worked as expected. check below:

Function code:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp2
{
    public class Function1
    {
        [FunctionName("Function1")]
        public void Run([TimerTrigger("0 0/1 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

The above function executed successfully in local. check below:

enter image description here

After, I published the function into portal successfully.

enter image description here

The function runs successfully in portal as well. check below:

enter image description here

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the help. really appreciate it. I can run locally and it works, cron works as well. Get the same output as you do locally. Can then publish to Azure portal. Where do I find the "Developer" - "Monitor" - "Invocation Traces" that is in your answer? In transaction search there is no Request what so ever and no trace contains the "timer trigger executed" so guess it's not running correctly for me? Haven't set AlwaysOn and from the link you posted it might have something to do with plan, I am running on Y1 which is a consumption plan though.
In transaction search I see in Trace Severity level: Information, Message: Host Status: { "id": "functionappjohantest", "state": "Running",
Also see that it might not be loading? It says in one trace "1 functions found (custom)" and then in the next trace "0 functions loaded"
JoBo, Can you redeploy the function once and check?
Once open the function which deployed into portal then you can see the monitor and invocation traces of function.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.