Back to Practical Aspnetcore

Logging Static File Servings

projects/file-provider/serve-static-files-8/README.md

latest486 B
Original Source

Logging Static File Servings

There may be a scenario where you need to log information about static file being served. This example shows you how.

public void Configure(IApplicationBuilder app, ILogger<Startup> logger)
{
    app.UseStaticFiles(new StaticFileOptions {
        OnPrepareResponse = ctx => {
            logger.LogInformation($"Serving static file: {ctx.File.Name}");
        }
    });
}    

Contribution by Lohit.