I have a C# .NET (4.6.1) Class Library that is being consumed by an Azure function app (V3). I am trying to get that Class Library to use the function app's App Insights for logging, but I'm completely lost on how to even start with setting it up correctly. I'm pretty sure I need the settings saved on the consuming function app, but not sure how to get the class library then to access those settings. Does anyone have any example code or suggestions on how to accomplish this?
Asked
Active
Viewed 536 times
1
-
If you connecting to azure application insights then you need only `instrumentation key` which can be read as Environment variable from the class library. – user1672994 Dec 18 '20 at 05:31
-
Normally you just take dependency on ILogger (from Microsoft.Extensions.Logging) and let whoever uses the library to deal with logging configuration... – Alexei Levenkov Dec 18 '20 at 05:41
-
Describe more details about your aim? E.g. I need to create a function with dotnet core and it will be triggered by http request and do xx things. And I need to use application insights to log key notes in running process. – Tiny Wang Dec 18 '20 at 05:54
1 Answers
0
When you create a class library, those ddl
s are consumed by other applications. Hence, they become a part of other applications.
So, for reading App Insights instrumentation key
in your class library, you have to use the following code:
ConfigurationManager.AppSettings.Get("DefaultConnectionString")
Using this will fetch setting DefaultConnectionString
from your consumer App's settings.

Harshita Singh
- 4,590
- 1
- 10
- 13