'Is it possible to send a message out to Log Stream (App Insights Logs) Inside Azure Function App

I feel like it must be possible, but I've yet to find an answer.

I navigate here inside of my Function App:

enter image description here

Then click the drop down arrow and select Application Insight Logs

enter image description here

As you can see in that picture, there's a log with an [Information] tag. I thought maybe I could do something like this in my Azure Function that's running my python script:

import logging
logging.info("Hello?")

However, I'm not able to get messages to show up in those logs. How do I actually achieve this? If there's a different place where logs created with logging.info() show up, I'd love to know that as well.

host.json file:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "logLevel": {
    "default": "Information",
    "Host.Results": "Information",
    "Function": "Information",
    "Host.Aggregator": "Information"
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "extensions": {
    "queues": {
      "batchSize": 2,
      "maxDequeueCount": 2
    }
  },
  "functionTimeout": "00:45:00"
}


Solution 1:[1]

I believe, there is no different place to write log info, but we need to change the log levels accordingly in host.json for getting different types of logs.

I tried to log the information level logs in this workaround.

  1. In VS Code, Created Azure Functions - Python Stack.
  2. Added this code logging.info(f" Calling Activity Function") in Activity Function Code like below:

enter image description here

This is the host.json code by default:

"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
        }
    }
}

After running this durable function, it is logging the information level:

enter image description here

Please refer to this workaround where I had given information about logging levels and also optimization of application insights logs on Azure Python Function.

Updated Answer:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1