示例#1
0
        /// <summary>
        /// 添加请求日志服务
        /// </summary>
        /// <param name="services">服务收藏</param>
        /// <param name="options">请求日志选项配置</param>
        /// <returns>服务收藏</returns>
        public static IServiceCollection AddRequestLog(this IServiceCollection services, Action <RequestLogOptions> options = null)
        {
            var apiExceptionHandleOptions = new RequestLogOptions();

            if (options != null)
            {
                options(apiExceptionHandleOptions);
            }

            services.AddSingleton <IOptions <RequestLogOptions> >(provider =>
            {
                return(Options.Create <RequestLogOptions>(apiExceptionHandleOptions));
            });

            return(services);
        }
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="next">下一个中间件处理委托</param>
 /// <param name="options">请求日志选项配置</param>
 /// <param name="log">日志</param>
 public RequestLogMiddleware(RequestDelegate next, IOptions <RequestLogOptions> options, ILogable log)
 {
     this.next    = next;
     this.options = options.Value;
     this.log     = log;
 }