Created
December 8, 2023 05:27
-
-
Save tonesandtones/6c3db9edc138be33b4bb1445215c3ca8 to your computer and use it in GitHub Desktop.
Simple logging middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Serilog": { | |
"**snip**": "**snipped irrelevant serilog config**", | |
"WriteTo": [ | |
{ | |
"Name": "File", | |
"Args": { | |
"path": "logs/log.log" | |
} | |
} | |
] | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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