|
@@ -195,6 +195,24 @@ internal static class StartupExtensions
|
|
|
|
|
|
internal static WebApplication ConfigurePipelines(this WebApplication app)
|
|
|
{
|
|
|
+ app.Use(async (context, next) =>
|
|
|
+ {
|
|
|
+ var loggerFactory = context.RequestServices.GetRequiredService<ILoggerFactory>();
|
|
|
+ var logger = loggerFactory.CreateLogger("RequestLogger");
|
|
|
+
|
|
|
+ var traceId = context.TraceIdentifier;
|
|
|
+ var scheme = context.Request.Scheme;
|
|
|
+ var method = context.Request.Method;
|
|
|
+ var path = context.Request.Path;
|
|
|
+ var queryString = context.Request.QueryString;
|
|
|
+
|
|
|
+ var request = $"{DateTime.Now} [{traceId}] {scheme} {method} {path}{queryString}";
|
|
|
+ logger.LogInformation(request);
|
|
|
+ await next.Invoke();
|
|
|
+ var response = $"{DateTime.Now} [{traceId}] {scheme} {method} {path} responsed";
|
|
|
+ logger.LogInformation(response);
|
|
|
+ });
|
|
|
+
|
|
|
app.UseSerilogRequestLogging();
|
|
|
|
|
|
var swaggerEnable = app.Configuration.GetSection("Swagger").Get<bool>();
|