I have a regular mvc app. How can I disable app insights from checking for favicon.ico?
CodePudding user response:
You can write a custom TelemetryFilter that prevents telemetry from being send to application insights:
public class CustomTelemetryFilter : ITelemetryProcessor
{
private readonly ITelemetryProcessor _next;
public CustomTelemetryFilter(ITelemetryProcessor next)
{
_next = next;
}
public void Process(ITelemetry item)
{
// Example: process all telemetry except requests to favicon
var isFavIconUrl = item is RequestTelemetry request && request.Url.ToString().EndsWith("favicon.ico");
if (!isFavIconUrl)
_next.Process(item); // Process the item only if it is not the request for favicon
}
}
The last step is to register your filter, see the docs on how to do that for your specific runtime.