serilog / serilog-aspnetcore

Serilog integration for ASP.NET Core
Apache License 2.0
1.32k stars 209 forks source link

Serilog.AspNetCore.RequestLoggingMiddleware HTTP "GET" "/" responded 404 #322

Closed arctumn closed 1 year ago

arctumn commented 1 year ago

Description

Serilog middleware calling an endpoint that does not exists in the controller.

This is only happening in this server, I have more servers running the same configuration of serilog.aspnetcore and none does this behavior.

image image

The only controller of the service:

image

Reproduction Please provide code samples showing how you're configuring and calling Serilog to produce the behavior.

Configuration via app-settings: image

Program.cs:


public class Program
    {
        public static void Main(string[] args)
        {

            var configuration = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile($"appsettings.{(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("Development") ? "Development." : "")}json")
               .Build();
            CreateHostBuilder(args, configuration).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args, IConfigurationRoot configuration) =>
            Host.CreateDefaultBuilder(args)
            .UseSerilog((context, cfg) => cfg.ReadFrom.Configuration(configuration))
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
    }

Expected behavior

Those calls should not being happening, that is a weird behavior to call endpoints that don't even exist.

Relevant package, tooling and runtime versions What Serilog version are you using, on what platform?

.NET 5.0

    <PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
    <PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.1.0" />

Additional context Add any other context about the problem here.

arctumn commented 1 year ago

After further inspecting, my micro-serices, I've noticed that the only one doing that error had this extra line uncommented:

image

I still don't think it's supposed to cause that effect.

To give more context: This micro-service is running under an Azure App Service container.

KravaNick commented 1 year ago

Most likely it's just HealthCheck on your server

nblumhardt commented 1 year ago

Hi @arctumn; as pointed out by @KravaNick - on the service with logging enabled, you can see which requests are being made, and there's a regular request to the / path that you weren't otherwise aware of (logging doing its job :-)).

Stack Overflow might be the place to get more help on App Service and what kind of health checks might be performed in that environment, if you need more info.