Configure LogLevel of Azure Function using environment variables












0














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 '18 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 '18 at 4:06












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
















0














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 '18 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 '18 at 4:06












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














0












0








0







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 '18 at 7:31









Jerry Liu

9,4031628




9,4031628










asked Nov 21 '18 at 3:51









Alasdair Stark

528424




528424












  • Have you checked logging configuration in host.json or you only want to work with environment variable?
    – Jerry Liu
    Nov 21 '18 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 '18 at 4:06












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


















  • Have you checked logging configuration in host.json or you only want to work with environment variable?
    – Jerry Liu
    Nov 21 '18 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 '18 at 4:06












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
















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






Have you checked logging configuration in host.json or you only want to work with environment variable?
– Jerry Liu
Nov 21 '18 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 '18 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 '18 at 4:06














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




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












1 Answer
1






active

oldest

votes


















1














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',
    autoActivateHeartbeat: false,
    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









    1














    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


























      1














      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
























        1












        1








        1






        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 '18 at 7:31









        Jerry Liu

        9,4031628




        9,4031628






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            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

            Costa Masnaga

            Fotorealismo

            Sidney Franklin