Azure Function N tier not logging to App Insights

Newbie Dev 151 Reputation points
2022-05-15T19:47:24.777+00:00

Hi,
I have an azure function app(v4), which is logging to App Insights.

The function app I have is n tier architecture, so it contains a function app project, domain and data layer.

The domain and data projects are .net 6 class libraries.

The logging seem to work fine with the function app project. There is instrumentation key setup in the Configuration tab in Azure Portal. I do not have any setup for app insights in the startup.cs file.

But the logging from the class libraries are not working. The class Library classes are injecting ILogger in the constructor to log the information/error. Is there any special setup needed for the logging to work?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,262 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,421 Reputation points
    2022-05-16T12:45:09.013+00:00

    Hi @Newbie Dev ,

    Thanks for reaching out to Q&A forum.

    You will have to use dependency injection design pattern to inject the iLogger into the other class libraries and register the service in the startup.cs.

    Please refer to the below sample code for more details about implementation,

    https://gist.github.com/nareshnagpal06/82c6b4df2a987087425c32adb58312c2

    I hope this helps! Feel free to reach out to me if you have any further queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments