Weird exception when trying to use Dependency Injection in an Azure Function

后端 未结 1 1944
离开以前
离开以前 2020-12-20 17:14

Given a File->New->Azure Functions v2 App, I\'m trying to get a reference to either an ILoggerFactory or an ILogger.

I\'m doing th

1条回答
  •  不知归路
    2020-12-20 17:16

    It seems that some infrastructure (e.g. IFileLoggingStatusManager) necessary for HostFileLoggerProvider is not set up yet at the time you are creating the dependency injection container and attempt to resolve the logger in the StartUp class. I think you should delay logging until after the application has fully started.

    If you look at the startup code of WebJobs you'll see that the logger gets added first, after that the external startup gets executed and finally the required logging services gets added. Which is the wrong order for your case.

    0 讨论(0)
提交回复
热议问题