Azure Function Logs Location

How To Store Logs in Azure Functions Which Can Be Accessed Later

This Azure tutorial will discuss the details of Azure Function logs’ location and where to see logs in Azure Functions.

Azure Function Logs Location

As we know, logs are essential for tracking how the Azure Function behaves. If the Azure Function fails or doesn’t work properly, we can analyze the logs to determine what happened.

The log details help us to fix the issue related to the Azure function in less time.

Azure Functions provides a tremendous built-in tool to store the log files related to the Azure Function, known as Azure Application Insights.

This excellent tool from Microsoft monitors your Azure Function closely and stores all the Logs, Performance, error data, Exceptions, etc., that help you troubleshoot your Azure Function in case of any issues or exceptions.

Now the question here is, Where To See Logs in Azure Functions

Default Azure Functions log location

While creating the Azure Functions app for the first time, we are configuring the Azure Storage account. If we navigate to the file service in the Storage account, you can find the host and function logs in the “/LogFiles/Application/Functions” directory.

View Log Data in Azure Function Monitor Tab

First, Enable Application Insights For Azure Functions

Once you enabled the Azure Application Insights, you can view the log data from the Monitor tab.

Navigate to the Azure Function App and click on the Functions option from the left navigation. Then, click the Monitor link from the left navigation on the Functions page.

An important point to remember is that the function must be run at least once after you enable the Application Insights option.

How To Store Logs in Azure Functions Which Can Be Accessed Later

You can click on each date on the Date (UTC) column to see the detailed log data for that particular date.

Now click on the Run query in the Application Insights link. It will provide details on the query’s source that retrieves the Azure Monitor Log Data. Since I was configuring this option for the first time, it showed me the below options, I clicked on the Get Started button.

Azure Functions logs in Application Insights in Azure Portal

It will now successfully configure the Azure Monitor Log Analytics tool, which helps provide insights from the Azure Monitor Logs.

Now, you can see the following query window. It provides you with the last 30 days’ log data.

Azure Functions Logging to Application Insights

Azure Functions Logging

The next thing is to open your Azure Function project. Open the local.settings.json file and add the code to provide the InstrumentationKey you copied above for your Application Insights.

{
  "ApplicationInsights": {
    "InstrumentationKey": "c854346f-8d4f-41c6-b692-767df3e8c6e3",
    "IsEncrypted": false,
    "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true",
      "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
  }
}

You have to provide the value for the InstrumentationKey as highlighted below.

azure function app insights ilogger

As you can see, the Azure function looks like the one below with the ILogger as the Parameter.

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

Now you can add the code for logging inside the Azure Function like below.

 log.LogInformation("hello checking the log");

Now the complete function looks like the below

[FunctionName("Function1")]
    
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
           
            string name = req.Query["name"];
            log.LogInformation("hello checking the log");
            
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
        }
    }

See it now

Azure Functions app Logging

Now you can Publish the function to Azure. Don’t forget to run and test the Azure function once in the Azure Portal by clicking on the Code + Test link from the left navigation on the Function page and then clicking on the Test/Run button from the top to run and test the function once.

Now navigate to the Application Insights we created above, click Search in the left navigation, and then click on the Refresh button at the top to get the updated contents.

azure functions v2 logging

Then, search for the text you put inside the Azure function code for logging. Now you can able to see the log for the same.

application insights logging

If you click on that, It will show you the details below

Logging with ILogger in Azure Functions

View Azure Function Log From Visual Studio 2019

You can see or view the log details stored in the table from Visual Studio. But before that, you make sure you have already installed the Azure SDK for your Visual Studio. Now, let’s see how to view the Logs from the Visual Studio 2019. Follow the below steps to view the logs in your Visual Studio 2019.

1. Open the Azure Functions Project you created in Visual Studio 2019.

2. The next step is to open the Cloud Explorer by Navigating to the option View —> Cloud Explorer

Azure Function Log To Blob Storage

3. On the Cloud Explorer window, expand the Storage Accounts and then expand the function app for which you want to see the logs. Now expand the Tables, and you can see AzureWebJobsHostLogs with the date.

How to send Azure Function logs to blob storage?

Now, if you open that, you can see the logs below

Azure Function Write To Blob Storage

Now, you click on each log to see the logs in details as below.

how to send azure function log to blob storage

View Azure Function Log From Azure Storage Explorer

You can also view the Azure Function logs from the Azure Storage Explorer. Follow the below steps to view the Azure Function logs using the Azure Storage Explorer.

Login to Azure Portal (https://portal.azure.com/) to copy the value for your App setting key Azure WebJobsStorage.

Once you log in to the Azure Portal, navigate to the Azure Function app for which you want to see the logs. On the Function App page, click on the Configuration from the left navigation.

View Azure Function Log From Azure Storage Explorer

Now, Under Application settings, locate the AzureWebJobsStorage and click on that link to get the value for the AccountName and AccountKey as highlighted below.

how to send azure function log using blob storage

Now copy the value, extract the account name and key, and keep them somewhere, as you will need to use those values in the Azure Storage Explorer.

View Azure Function Log using Azure Storage Explorer

Now open the Azure Storage Explorer that you installed on your machine before. If you haven’t installed it yet, you can install it now.

Now, use the Account name and the Account key you have copied in your Azure Storage Explorer to retrieve the log details for your Azure Functions. Follow the below steps in the Azure Storage Explorer.

Open the Azure Storage Explorer from your machine and click the Open Connect Dialog button on the left.

How to View Azure Function Log using Azure Storage Explorer

Select “Use a storage account name and key” from the below Pop-up and click the Next button.

How to View Azure Function Log from Azure Storage Explorer

Now provide the below details on the Connect with Name and Key window

  • Display Name: Provide a name for the connection
  • Account name: Provide the Account name that you copied before, as mentioned in the above steps.
  • Account Key: Provide the Account key that you copied before, as mentioned in the above steps.
  • Storage Domain: Select the Azure storage domain option and click the Next button.
How to View Azure Function Log in Azure Storage

On the Connection Summary page, validate previously provided details and click the Connect button to establish the Azure connection.

Azure Function Logs To Blob Storage

Now, it created a connection with the name that we provided. If you expand the connection name and then expand the Tables, you can see the AzureWebJObsHostLogs with the date highlighted below.

Azure Function Logs To Blob Storage configuration

Now, if you click on that, you can see the list of logs below

Monitoring Azure Functions with Azure Monitor Logs

This is how we can access Azure Function Log From Visual Studio 2019 and View Azure Function Log From Azure Storage Explorer.

You may also like following the below Articles

Wrapping Up

In this article, we have discussedthe details of Azure Function logs location and where to see logs in Azure Functions.