Search code examples
c#.netazure-functionsazure-functions-runtimeazure-functions-core-tools

Azure Functions Logging


In Azure Functions you use host.json to configure logging. However, the logging options/sections are unclear to me. Can someone help?

Per this: https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json

  "logging": {
        // FILE CONFIG?
        "fileLoggingMode": "debugOnly"
        "logLevel": {
          "Function.MyFunction": "Information", // where is this log?
          "default": "None"
        },
        // INSIGHTS CONFIG
        "applicationInsights": {
            "samplingSettings": {
              "isEnabled": true,
              "excludedTypes" : "Dependency;Event",
              "includedTypes" : "PageView;Trace"
            },
  1. Is the FILE CONFIG section used for logging in "log stream"? or is the INSIGHT section? enter image description here

  2. What is 'default' vs 'Function" log level?

I assume Filesystem logs is what controlled via FILE CONFIG section, correct?

  1. What configuration is used for "Monitor" section of Azure Functions?, is it FILE CONFIG? if so, If I wanted to see only errors under "Monitor" section would I set Function.MyFunction": "Error" or "default"?

enter image description here


Solution

    1. FileLoggingMode is used to generate the logs in azure portal or in a local Environment. The different modes in “fileLoggingMode” are

    “debugOnly”: This level will generate logs when the function app is running on Azure Portal. This is the default mode.

    “always”: This mode is used to generate logs in local environment as well as when running on Azure Portal. This code reference can be helpful to understand it better.

    “never”: This mode does not generate any logs.

    When the “fileLoggingMode” is set to “always” the log file generated when running in local environment is stored in “C:\Users{user}\AppData\Local\Temp\LogFiles\Application\Functions\Function{Function_Name}”, the path can be referenced here in the Host Settings code. If you are running the function app as docker/container in your local premises you can change the path by updating the host configuration code.

    The fileLoggingMode is still in issue see here

    1. Default Vs Function log is both are same level check the below json

    In a logging loglevel we have Parameters default/function/… we where mention the Which type of log can we need to get like (error, information, trace, ….)

    {
    "logging": {
        "fileLoggingMode": "always",
        "logLevel": {
            "default": "Information",
            "Function": "Error"
            }
        }
    }
    

    Refer: Configure monitoring for Azure Functions | Microsoft Docs

    1. In a default it get the log information of what you added in a parameter (host.json). If you are using "default": "Error" you will get the Error logs by default.

    If you are using below configuration by default it will get the Information Log and Funcition get the Error log.

    "default": "Information",
    
    "Function": "Error"