示例#1
0
        /// <summary>
        /// This will affect performance.
        /// This should be called before anything else, including error handling, as it needs to create a new response stream.
        /// </summary>
        public static IApplicationBuilder UseResponseLogging(this IApplicationBuilder builder, Action <ResponseLoggingOptions> setupAction = null)
        {
            var options = new ResponseLoggingOptions();

            setupAction?.Invoke(options);

            return(builder.UseResponseLogging(options));
        }
示例#2
0
        /// <summary>
        /// This will affect performance.
        /// This should be called before anything else, including error handling, as it needs to create a new response stream.
        /// </summary>
        private static IApplicationBuilder UseResponseLogging(this IApplicationBuilder builder, ResponseLoggingOptions options)
        {
            if (options == null)
            {
                options = new ResponseLoggingOptions();
            }

            if (options.Enabled)
            {
                var logger = builder.ApplicationServices.GetRequiredService <ILoggerFactory>().CreateLogger(options.LoggerName ?? typeof(ResponseLoggingMiddleware).Namespace);
                builder.UseMiddleware <ResponseLoggingMiddleware>(logger, options.MaxBodyByteCount, options.ShouldLog ?? (ctx => true), options.LogPrefix);
            }

            return(builder);
        }