Skip to content

Instantly share code, notes, and snippets.

@tonesandtones
Created December 8, 2023 05:27
Show Gist options
  • Save tonesandtones/6c3db9edc138be33b4bb1445215c3ca8 to your computer and use it in GitHub Desktop.
Save tonesandtones/6c3db9edc138be33b4bb1445215c3ca8 to your computer and use it in GitHub Desktop.
Simple logging middleware
"Serilog": {
"**snip**": "**snipped irrelevant serilog config**",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "logs/log.log"
}
}
]
},
// TODO: REMOVE
app.Use(async (ctx, next) => {
var logger = app.ApplicationServices.GetRequiredService<ILogger>();
var path = ctx.Request.Path;
logger.LogInformation($"Path = {path}");
foreach (var header in ctx.Request.Headers.ToList())
{
string value = string.Join(':', header.Value.ToList());
logger.LogInformation($"Header '{header.Key}' = '{value}'");
}
await next(ctx);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment