I am developing an asp.net gateway application on top of Ocelot. I am using Serilog as a logger.
Problem: Ocelot package itself is not writing to this logfile, for example, bad requests etc, even though lot of logging calls sprinkled throughout Ocelot.
Whatever I myself am logging, using Log.Information etc, is being logged.
Here is my main program in .NET 8 (simplified):
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
configuration.AddJsonFile($"ocelot.{env}.json", optional: false, reloadOnChange: true);
var services = builder.Services;
...
services.AddOcelot();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Log.Information("Ocelot gateway app starting up"); //this is being logged correctly
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.UseOcelot().Wait();
app.Run();
Here is my appsettings.file
"Serilog": {
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": { "path": "C:\temp\ocelot\logs-staging.txt" }
}
]
}