question

NewbieDev-4631 avatar image
0 Votes"
NewbieDev-4631 asked MughundhanRaveendran-MSFT commented

Azure Function N tier not logging to App Insights

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@NewbieDev-4631 ,

Following up to see if the above answer helps. Do let me know if you have any queries.

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 Votes 0 ·

1 Answer

MughundhanRaveendran-MSFT avatar image
0 Votes"
MughundhanRaveendran-MSFT answered

Hi @NewbieDev-4631 ,

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.