Configure LogLevel of Azure Function using environment variables











up vote
0
down vote

favorite












As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.



In the following example, an instance of ILogger is injected into the Run method of the function.



[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}


When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.



In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:



"logging__logLevel__Default: "Error" 









share|improve this question
























  • Have you checked logging configuration in host.json or you only want to work with environment variable?
    – Jerry Liu
    Nov 21 at 3:56












  • I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
    – Alasdair Stark
    Nov 21 at 4:06












  • Manual edit is the only way, generation is controlled by Azure function template engine for VS.
    – Jerry Liu
    Nov 21 at 4:14















up vote
0
down vote

favorite












As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.



In the following example, an instance of ILogger is injected into the Run method of the function.



[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}


When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.



In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:



"logging__logLevel__Default: "Error" 









share|improve this question
























  • Have you checked logging configuration in host.json or you only want to work with environment variable?
    – Jerry Liu
    Nov 21 at 3:56












  • I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
    – Alasdair Stark
    Nov 21 at 4:06












  • Manual edit is the only way, generation is controlled by Azure function template engine for VS.
    – Jerry Liu
    Nov 21 at 4:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.



In the following example, an instance of ILogger is injected into the Run method of the function.



[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}


When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.



In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:



"logging__logLevel__Default: "Error" 









share|improve this question















As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.



In the following example, an instance of ILogger is injected into the Run method of the function.



[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}


When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.



In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:



"logging__logLevel__Default: "Error" 






azure asp.net-core azure-functions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 7:31









Jerry Liu

7,2131427




7,2131427










asked Nov 21 at 3:51









Alasdair Stark

513421




513421












  • Have you checked logging configuration in host.json or you only want to work with environment variable?
    – Jerry Liu
    Nov 21 at 3:56












  • I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
    – Alasdair Stark
    Nov 21 at 4:06












  • Manual edit is the only way, generation is controlled by Azure function template engine for VS.
    – Jerry Liu
    Nov 21 at 4:14


















  • Have you checked logging configuration in host.json or you only want to work with environment variable?
    – Jerry Liu
    Nov 21 at 3:56












  • I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
    – Alasdair Stark
    Nov 21 at 4:06












  • Manual edit is the only way, generation is controlled by Azure function template engine for VS.
    – Jerry Liu
    Nov 21 at 4:14
















Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56






Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 at 3:56














I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06






I would like to see if it's possible to control LogLevel using environment variables but I wasn't familiar with the host.json file. When debugging the Function locally using the emulator, I can see that a host.json file is automatically generated but does not contain any logging config. When I edit the file manually I can successfully set the log level. Can I control the generation of this file when developing locally?
– Alasdair Stark
Nov 21 at 4:06














Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14




Manual edit is the only way, generation is controlled by Azure function template engine for VS.
– Jerry Liu
Nov 21 at 4:14












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json to change log level.



v2 log configuration in host.json.



"logging": {
"logLevel": {
// For specific function
"Function.MyFunction1": "Information",
// For all functions
"Function":"Error",
// Default settings, e.g. for host
"default": "None"
}
}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405020%2fconfigure-loglevel-of-azure-function-using-environment-variables%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json to change log level.



    v2 log configuration in host.json.



    "logging": {
    "logLevel": {
    // For specific function
    "Function.MyFunction1": "Information",
    // For all functions
    "Function":"Error",
    // Default settings, e.g. for host
    "default": "None"
    }
    }





    share|improve this answer

























      up vote
      0
      down vote



      accepted










      I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json to change log level.



      v2 log configuration in host.json.



      "logging": {
      "logLevel": {
      // For specific function
      "Function.MyFunction1": "Information",
      // For all functions
      "Function":"Error",
      // Default settings, e.g. for host
      "default": "None"
      }
      }





      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json to change log level.



        v2 log configuration in host.json.



        "logging": {
        "logLevel": {
        // For specific function
        "Function.MyFunction1": "Information",
        // For all functions
        "Function":"Error",
        // Default settings, e.g. for host
        "default": "None"
        }
        }





        share|improve this answer












        I am afraid we can't configure the log level using environment variables. When function host starts, it reads log level from host.json and inject ILogger instance with corresponding filter rules. Host configurations are not env variables, but we can modify host.json to change log level.



        v2 log configuration in host.json.



        "logging": {
        "logLevel": {
        // For specific function
        "Function.MyFunction1": "Information",
        // For all functions
        "Function":"Error",
        // Default settings, e.g. for host
        "default": "None"
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 7:31









        Jerry Liu

        7,2131427




        7,2131427






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405020%2fconfigure-loglevel-of-azure-function-using-environment-variables%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...