I see a lot of GET Home/Index
requests in the application insight logs (1500 messages in every 30 minutes). I am looking for a way / solution to stop logging these requests.
I have the following code in the code in the configuration.
.UseSerilog((host, logger) => {
var appInsightsOptions = configuration.GetRequiredSection("AppInsights").Get<AppInsightsOptions>();
var telemetryConfiguration = new TelemetryConfiguration(appInsightsOptions.InstrumentationKey);
logger
.MinimumLevel.Warning()
.Enrich.FromLogContext()
.Enrich.WithProperty("ApplicationName",host.HostingEnvironment.ApplicationName)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Events);
})
Below is the web.cs and appsettings.json file content.
using System.Collections.Generic;
using System.Fabric;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
using Microsoft.Extensions.Logging;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Microsoft.Extensions.Configuration;
using System;
namespace projectname
{
internal sealed class Web : StatelessService
{
public Web(StatelessServiceContext context)
: base(context)
{ }
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
var currentEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{currentEnvironment}.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
return new WebHostBuilder()
.UseKestrel()
.UseConfiguration(configuration)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext)
.AddSingleton<ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.UseSerilog((host, logger) => {
//Get Configuration
var appInsightsOptions = configuration.GetRequiredSection("AppInsights").Get<AppInsightsOptions>();
var telemetryConfiguration = new TelemetryConfiguration(appInsightsOptions.InstrumentationKey);
logger
.MinimumLevel.Warning()
.Enrich.FromLogContext()
.Enrich.WithProperty("ApplicationName",host.HostingEnvironment.ApplicationName)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Events);
})
.Build();
}))
};
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AppInsights": {
"InstrumentationKey": "XXXXXXXXXXXXXXXX"
},
"AllowedHosts": "*"
}
I am using service fabric application and the configuration is added in the web.cs file.
Initial Output:
To prevent the Serilog from logging
home/index
or any other endpoint request, Add the below line of code.My
Program.cs
file:My
appsettings.json
file:Final Output (without endpoints
/
):