In my Function Application (v2) I have a function probe that is used to test the health of my application and is called every few seconds. I would like to stop logging anything from that specific function to Application Insights.
The function probe looks like this:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using MyApp.Api.Hello;
namespace MyApp.Api
{
public static class HealthFunctions
{
[FunctionName("probe")]
public static IActionResult Probe(
[HttpTriggerAttribute(AuthorizationLevel.Anonymous, "get")] HttpRequest request,
ILogger logger)
{
return new OkResult();
}
}
}
And host.json:
{
"version": "2.0",
"extensions": {
"http": {
"routePrefix": ""
}
},
"logging": {
"logLevel": {
"Function.probe": "Error",
"default": "Trace"
}
}
}
However I am still seeing the telemetry in Application Insights sent by calling /probe:
What I am doing wrong?
Update 12/09:
Yes, your comment is correct, there is still some messages about it can be logged into application insights. But any messages logged by log.LogInformation()
method and should not be written into application insights.
And I find another way can avoid it, you can specify the loglevel for all other function apps; but not for the function app you don't want to log to application insights, do not specify loglevel for it. Then you can specify the default as None, which can completely avoid this function app to log into application insights.
Here is an example:
I have 3 function apps, and I don't want the function named HttpTrigger1 to log into application insights. So in host.json, I specify the loglevel to Trace for the other 2 function apps: BlobTrigger1 and QueueTrigger1. And set the default as None.
The host.json at my side:
{
"version": "2.0",
"extensions": {
"http": {
"routePrefix": ""
}
},
"logging": {
"logLevel": {
"Function.BlobTrigger1": "Trace",
"Function.QueueTrigger1": "Trace",
"default": "None"
}
}
}
The screenshot:
It works as expected, no logs from "HttpTrigger1" are written into Application Insights.
For disable logging to application insights from a specific azure function, in the host.json, you can specify logLevel as None for that azure function(in your case, it's probe). Sample host.json looks like below:
{
"version": "2.0",
"extensions": {
"http": {
"routePrefix": ""
}
},
"logging": {
"logLevel": {
"Function.probe": "None",
"default": "Trace"
}
}
}
Then only the function named "probe" cannot send data to application insights.
And here is one thing you should note, in the specified azure function -> Monitor, there is a empty log created(see screenshot below), this "empty log" means that no logs are written into application insights(You can just write a query in application insights to confirm this. I tested it with log query, no logs are shown in application insights for that specified azure function).