I have an Azure Functions project that was deployed to a Function App for dev/test and was successfully writing log messages to Application Insights. I published the same project to a new Function App, in the same Azure subscription and now neither App logs anything to Application Insights.
The project was deployed using Visual Studio (15.8.7 with Azure Functions and Web Jobs Tools 15.9.02009.0).
I tried adding a logger entry to host.json to explicitly set the Function category log level to information.
The Azure Functions and Web Jobs Tools extension is up to date in Visual Studio.
I also tried deleting the APPINSIGHTS_INSTRUMENTATIONKEY application setting, and restarting the App, so that then when I clicked on the Monitor tab for one of the functions it went through the wizard to configure Application Insights. At the end of that though, it displayed the message "your app is offline or the application insights sdk needs updating".
Any ideas what could be wrong?
Another confusing source of logging not showing up is injecting loggers into components inside your functions project. For instance you can inject a Logger<T>
into something in your function
namespace ThingyFunctions{
public class Thingy
{
public Thingy(ILogger<Thingy> log)
{
this.log = log;
}
[FunctionName(nameof(Thingy)]
public async Task Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer)
{
log.LogInformation("Some message here");
}
}
}
That log message will be filtered out by default. You can see it by changing the log level in your host.json
"logging": {
"logLevel": {
"default": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false
}
}
}
That will capture everything at the Information level. You can also do it by namespace
"logging": {
"logLevel": {
"ThingyFunctions": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false
}
}
}
I believe you can also do it by function name
"logging": {
"logLevel": {
"Function.Thingy": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false
}
}
}
Hmm. Looks like there was a glitch in the matrix. I'm not sure what part of the matrix though - Azure portal/App Insights etc.
Monitoring is working now though.
Looks like it started working around the time I deleted the APPINSIGHTS_INSTRUMENTATIONKEY and reconfigured it, but entries didn't show up in the portal until over an hour later.
Even though the OP has resolved his issue I've found out another possibility for logs to suddenly disappear. There is this feature called sampling. It basically says that if there is much to log it'll choose what to log randomly (or semi-randomly). And it's enabled by default. Long story short, in order to configure it one has to adjust the host.json
file.
Specifically, in order to disable the sampling completely one has to add the following:
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": false
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With