Search code examples
c#azureazure-functionsazure-functions-runtime

How to get Azure Function name from within a function?


My goal is to provide a code snippet to customers. One file will contain customer's business logic, another file will provide its handling. For the latter I need to have a name of a function [would like to avoid asking customers to enter this information manually].

I searched around but could not figure out. Essentially I need this:

enter image description here


Solution

  • The ExecutionContext class has a property FunctionName (docs)

    You can inject the class like this:

    [FunctionName("HttpTriggered")]
    public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
         HttpRequest req, 
         ExecutionContext executionContext)
    {
         var name = executionContext.FunctionName;
         ...
    }
    

    The output will be

    HttpTriggered

    Update 11-2025

    For isolated runtime functions things are more complicated and you need the FunctionContext class and use FunctionDefinition.Name. See the docs. However, this class cannot be used using DI, see this issue. But, a workaround is presented in that same issue.