3
votes

I've got a simple C# Azure Function using a timer trigger to run every X minutes. No output binding.

In application insights, the function is always in success with a result code of 0:

Here

[Despite having called the .Error() of the TraceWriter several times.]

I'd like to get the correct final status in application insights but I don't see how to do it. Documentation never talks about that :-/ Can someone guide me how to do it in C# ?

I tried to set Environment.ExiCode but same result. I also tried to change return type to int but then the function isn't called anymore. I suppose because its the way to declare an output binding for the azure function itself.

Here is my function:

[FunctionName("SendToOfflineArchive")]
public static void Run([TimerTrigger("%TimerInterval%")]TimerInfo myTimer, TraceWriter log)
{
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");

    // do stuff

    int nbErrors = 7;
    //return nbErrors;
}

It would be great to have a result code other than 0... Like the number of errors (an integer).

1
Hi Thibault, how did you create this function using Visual studio or directly on the portal? I think TraceWriter is old signature. Take a look at this docs.microsoft.com/en-us/azure/azure-functions/… - Anass Kartit
It's a 7 months-"old" project using the Functions 1.x and working fine. However same issue with version 2.x. Anyhow the logger is not the problem! - Thibault ROHMER

1 Answers

2
votes

Azure Function is considered failed if it threw an exception (there is an embedded integration between AF and AI and it considers successfully executed function a "success"). Logging an error as a trace should yield corresponding Trace message in Application Insights if logging forwarding is enabled.