Azure Function Logging

Recently, I had a chance to implement Azure Function Logging for one of my Azure Function projects. The information provided in this article will help you to understand that.

Azure Functions Logging

By default, the Ilogger instance was present with the Azure Function Signature. The Azure Function with ILogger instance looks like the one below. This is the code sample for Azure function logging using c#.

        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)

You can see the same in the below screeshot.

azure function logging c#

The instance of ILogger will be there as the parameter of the Azure Function, as shown above.

If you see the Azure Function logging level, with the ILogger instance, you can log information, LogError, LogWarning, LogDebug, LogTrace, LogCritical, etc. You can take a look below.

public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
            log.LogInformation("C# HTTP trigger function processed a request.");
            log.LogError("Error details");
            log.LogWarning("Warning Details");
            log.LogDebug("Log Debug Details");
            log.LogTrace("Log Trace Details");
            log.LogCritical("LogCritical details");

Along with the information, you can append the actual value, For Example, the actual Exception Details.

Above are the examples of the Azure Function with the C# language.

In the case of the JavaScript Azure Function, you can implement in the following ways

module.exports = async function(context, myTrigger, Input1, Input2)

The context object has a log() function and a log object. You call the appropriate log functions based on your requirements.

context.log.warn( "Warning Details" )
context.log.error( "Error details" ) "Information Details" )
context.log.verbose( "Details" )
context.log( "Put the Details")

You can check out Azure Function Ilogger for more information.

You may also like following the articles below


This article discussed the Azure Function Logging option for C# and Javascript Azure Functions. Thanks for reading this article !!!