Exemple #1
0
        public OwinMiddlewareLogger(OwinMiddleware next, IAppBuilder app, IReadOnlyList <object> args) : base(next)
        {
            _next = next;
            //_app = app;

            _httpLoggerRepository = (HttpLoggerRepository)args[0];
            _isLoggingEnabled     = (bool)args[1];
            // _httpLoggerRepository = new HttpLoggerRepository(connFactory);
            //_isLoggingEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["HttpLoggerEnabled"]);
        }
 /// <summary>
 /// In order to capture the full set of data during a HTTP request this OWIN plugin must be the first plugin in the chain.
 /// 
 /// Configure OWIN to trace HTTP requests and responses. Note that capturing request query parameters and request and response data could cause
 /// data security issues - potentially sensitive data will be logged to Azure table storage.
 /// 
 /// Therefore by default none of this is captured.
 /// 
 /// </summary>
 /// <param name="appBuilder">The OWIN app builder</param>
 /// <param name="loggerRepository">The repository to use for storing http logs</param>
 /// <param name="captureRequestParams">True if you wish to capture query parameters, false if not.</param>
 /// <param name="captureRequestData">True if you wish to capture request data, false if not.</param>
 /// <param name="captureResponseData">True if you wish to capture response data, falise if not.</param>
 /// <param name="captureRequestHeaders">To capture all request headers set a single array element of "*" otherwise specify the headers you wish to capture.</param>
 /// <param name="captureResponseHeaders">To capture all response headers set a single array element of "*" otherwise specify the headers you wish to capture.</param>
 /// <param name="httpCorrelationHeaderKey">
 /// It can be helpful when calling across http boundaries to be able to tie together the flow of events with a correlation ID and by default the logger
 /// looks for a correlation ID in the header correlation-id. If the header is missing then no correlation ID is used but the logger will work. If you
 /// wish to disable this behaviour then set this to null or if you want to use a different header then set the header name here.
 /// 
 /// The HttpCorrelator middleware also in this assembly can be used to add a correlation ID if none is present and should be placed before the logger middleware
 /// in the pipeline.
 /// </param>
 /// <returns></returns>
 public static IAppBuilder UseHttpLogger(this IAppBuilder appBuilder,
     IHttpLoggerRepository loggerRepository,
     bool captureRequestParams = false,
     bool captureRequestData = false,
     bool captureResponseData = false,
     string[] captureRequestHeaders = null,
     string[] captureResponseHeaders = null,
     string httpCorrelationHeaderKey = "correlation-id")
 {
     appBuilder.Use<HttpLogger>(
         loggerRepository,
         captureRequestParams,
         captureRequestData,
         captureResponseData,
         captureRequestHeaders,
         captureResponseHeaders,
         httpCorrelationHeaderKey);
     return appBuilder;
 }
Exemple #3
0
 /// <summary>
 /// In order to capture the full set of data during a HTTP request this OWIN plugin must be the first plugin in the chain.
 ///
 /// Configure OWIN to trace HTTP requests and responses. Note that capturing request query parameters and request and response data could cause
 /// data security issues - potentially sensitive data will be logged to Azure table storage.
 ///
 /// Therefore by default none of this is captured.
 ///
 /// </summary>
 /// <param name="appBuilder">The OWIN app builder</param>
 /// <param name="loggerRepository">The repository to use for storing http logs</param>
 /// <param name="captureRequestParams">True if you wish to capture query parameters, false if not.</param>
 /// <param name="captureRequestData">True if you wish to capture request data, false if not.</param>
 /// <param name="captureResponseData">True if you wish to capture response data, falise if not.</param>
 /// <param name="captureRequestHeaders">To capture all request headers set a single array element of "*" otherwise specify the headers you wish to capture.</param>
 /// <param name="captureResponseHeaders">To capture all response headers set a single array element of "*" otherwise specify the headers you wish to capture.</param>
 /// <param name="httpCorrelationHeaderKey">
 /// It can be helpful when calling across http boundaries to be able to tie together the flow of events with a correlation ID and by default the logger
 /// looks for a correlation ID in the header correlation-id. If the header is missing then no correlation ID is used but the logger will work. If you
 /// wish to disable this behaviour then set this to null or if you want to use a different header then set the header name here.
 ///
 /// The HttpCorrelator middleware also in this assembly can be used to add a correlation ID if none is present and should be placed before the logger middleware
 /// in the pipeline.
 /// </param>
 /// <returns></returns>
 public static IAppBuilder UseHttpLogger(this IAppBuilder appBuilder,
                                         IHttpLoggerRepository loggerRepository,
                                         bool captureRequestParams       = false,
                                         bool captureRequestData         = false,
                                         bool captureResponseData        = false,
                                         string[] captureRequestHeaders  = null,
                                         string[] captureResponseHeaders = null,
                                         string httpCorrelationHeaderKey = "correlation-id")
 {
     appBuilder.Use <HttpLogger>(
         loggerRepository,
         captureRequestParams,
         captureRequestData,
         captureResponseData,
         captureRequestHeaders,
         captureResponseHeaders,
         httpCorrelationHeaderKey);
     return(appBuilder);
 }
Exemple #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="next">The next piece of middleware to call</param>
        /// <param name="httpLoggerRepository">The repository to store the http information in</param>
        /// <param name="captureRequestParams">True if query parameters should be captured, false if they should be removed</param>
        /// <param name="captureRequestData">True if request data should be persisted to storage, false if not. Currently true is unsupported.</param>
        /// <param name="captureResponseData">True if response data should be persisted to storage, false if not. Currently true is unsupported.</param>
        /// <param name="captureRequestHeaders">The set of request headers to capture, a single item of "*" for all headers</param>
        /// <param name="captureResponseHeaders">The set of response headers to capture, a single item of "*" for all headers</param>
        /// <param name="httpCorrelationHeaderKey">The name of the header to use for a correlation ID</param>
        public HttpLogger(OwinMiddleware next,
                          IHttpLoggerRepository httpLoggerRepository,
                          bool captureRequestParams,
                          bool captureRequestData,
                          bool captureResponseData,
                          IEnumerable <string> captureRequestHeaders,
                          IEnumerable <string> captureResponseHeaders,
                          string httpCorrelationHeaderKey) : base(next)
        {
            if (captureRequestData || captureResponseData)
            {
                throw new NotSupportedException("Not yet supported - arriving in v1");
            }

            _httpLoggerRepository     = httpLoggerRepository;
            _captureRequestParams     = captureRequestParams;
            _httpCorrelationHeaderKey = httpCorrelationHeaderKey;
            //_captureRequestData = captureRequestData;
            //_captureResponseData = captureResponseData;
            _captureRequestHeaders  = captureRequestHeaders.ToArray();
            _captureResponseHeaders = captureResponseHeaders.ToArray();
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="next">The next piece of middleware to call</param>
 /// <param name="httpLoggerRepository">The repository to store the http information in</param>
 /// <param name="captureRequestParams">True if query parameters should be captured, false if they should be removed</param>
 /// <param name="captureRequestData">True if request data should be persisted to storage, false if not. Currently true is unsupported.</param>
 /// <param name="captureResponseData">True if response data should be persisted to storage, false if not. Currently true is unsupported.</param>
 /// <param name="captureRequestHeaders">The set of request headers to capture, a single item of "*" for all headers</param>
 /// <param name="captureResponseHeaders">The set of response headers to capture, a single item of "*" for all headers</param>
 /// <param name="httpCorrelationHeaderKey">The name of the header to use for a correlation ID</param>
 public HttpLogger(OwinMiddleware next,
     IHttpLoggerRepository httpLoggerRepository,
     bool captureRequestParams,
     bool captureRequestData,
     bool captureResponseData,
     IEnumerable<string> captureRequestHeaders,
     IEnumerable<string> captureResponseHeaders,
     string httpCorrelationHeaderKey) : base(next)
 {
     if (captureRequestData || captureResponseData)
     {
         throw new NotSupportedException("Not yet supported - arriving in v1");
     }
     
     _httpLoggerRepository = httpLoggerRepository;
     _captureRequestParams = captureRequestParams;
     _httpCorrelationHeaderKey = httpCorrelationHeaderKey;
     //_captureRequestData = captureRequestData;
     //_captureResponseData = captureResponseData;
     _captureRequestHeaders = captureRequestHeaders.ToArray();
     _captureResponseHeaders = captureResponseHeaders.ToArray();
 }
Exemple #6
0
        public async Task InvokeAsync(HttpContext context, IHttpLoggerRepository loggerRepository)
        {
            var log = new HttpLogModel
            {
                Path        = context.Request.Path,
                Method      = context.Request.Method,
                QueryString = context.Request.QueryString.ToString(),
                IpAddress   = context.Request.HttpContext.Connection.RemoteIpAddress.ToString()
            };

            if (context.Request.Method == "POST")
            {
                context.Request.EnableBuffering();
                var body = await new StreamReader(context.Request.Body)
                           .ReadToEndAsync();
                context.Request.Body.Position = 0;
                log.Payload = body;
            }

            log.RequestedOn = DateTime.Now;
            loggerRepository.Add(log);
            await _next(context);
        }