How can I use the new DI to inject an ILogger into an Azure Function using IWebJobsStartup?

前端 未结 5 1806
后悔当初
后悔当初 2021-02-04 03:18

I am using Azure Function v2. Here is my function that uses the constructor injection:

public sealed class FindAccountFunction
{
    private readonl         


        
5条回答
  •  广开言路
    2021-02-04 03:38

    In addition to registering the class in function Startup class, we would need to add the namespace in host.json file as well in order to log the messages to App insights. If we don't add it, it will simply log the message to console locally but when deployed on azure, it won't log anything and won't give any error either.

    {
      "version": "2.0",
      "logging": {
        "logLevel": {
          "FunctionProjectNameSpace.RegisteredClass": "Information"
        }
      }
    }
    

    Sample code here for reference - https://gist.github.com/nareshnagpal06/82c6b4df2a987087425c32adb58312c2

提交回复
热议问题