You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1015 B
33 lines
1015 B
|
|
using CoreAgent.Infrastructure.Options;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Serilog;
|
|
|
|
namespace CoreAgent.Infrastructure.Extensions.Logging;
|
|
|
|
/// <summary>
|
|
/// 请求日志扩展方法
|
|
/// </summary>
|
|
public static class RequestLoggingExtensions
|
|
{
|
|
/// <summary>
|
|
/// 添加请求日志中间件
|
|
/// </summary>
|
|
/// <param name="app">应用程序构建器</param>
|
|
/// <returns>应用程序构建器</returns>
|
|
|
|
public static IServiceCollection AddRequestLogging(this IServiceCollection services, IConfiguration config)
|
|
{
|
|
services.Configure<RequestLoggingOptions>(config.GetSection("RequestLogging"));
|
|
return services;
|
|
}
|
|
|
|
public static IApplicationBuilder UseRequestLogging(this IApplicationBuilder app, IConfiguration config)
|
|
{
|
|
app.UseMiddleware<RequestLoggingMiddleware>();
|
|
app.UseMiddleware<ResponseLoggingMiddleware>();
|
|
return app;
|
|
}
|
|
}
|