public void Log(IRequestContext requestContext, object requestDto, object response)
        {
            var requestType = requestDto != null?requestDto.GetType() : null;

            if (ExcludeRequestDtoTypes != null &&
                requestType != null &&
                ExcludeRequestDtoTypes.Contains(requestType))
            {
                return;
            }

            var httpReq = requestContext.Get <IHttpRequest>();
            var entry   = new RequestLogEntry {
                Id           = Interlocked.Increment(ref requestId),
                DateTime     = DateTime.UtcNow,
                HttpMethod   = httpReq.HttpMethod,
                AbsoluteUri  = httpReq.AbsoluteUri,
                PathInfo     = httpReq.PathInfo,
                IpAddress    = requestContext.IpAddress,
                ForwardedFor = httpReq.Headers[HttpHeaders.XForwardedFor],
                Referer      = httpReq.Headers[HttpHeaders.Referer],
                Headers      = httpReq.Headers.ToDictionary(),
                UserAuthId   = httpReq.GetItemOrCookie(HttpHeaders.XUserAuthId),
                SessionId    = httpReq.GetSessionId(),
                Items        = httpReq.Items,
                Session      = EnableSessionTracking ? httpReq.GetSession() : null,
            };

            if (HideRequestBodyForRequestDtoTypes != null &&
                requestType != null &&
                !HideRequestBodyForRequestDtoTypes.Contains(requestType))
            {
                entry.RequestDto = requestDto;
                entry.FormData   = httpReq.FormData.ToDictionary();
            }
            if (response.IsErrorResponse())
            {
                if (EnableResponseTracking)
                {
                    entry.ResponseDto = response;
                }
            }
            else
            {
                if (EnableErrorTracking)
                {
                    entry.ErrorResponse = ToSerializableErrorResponse(response);
                }
            }

            logEntries.Enqueue(entry);

            RequestLogEntry dummy;

            if (logEntries.Count > capacity)
            {
                logEntries.TryDequeue(out dummy);
            }
        }
        private void ConfigureRequestLogger(IAppHost appHost)
        {
            var requestLogger = Logger;

            requestLogger.EnableSessionTracking             = EnableSessionTracking;
            requestLogger.EnableResponseTracking            = EnableResponseTracking;
            requestLogger.EnableRequestBodyTracking         = EnableRequestBodyTracking;
            requestLogger.EnableErrorTracking               = EnableErrorTracking;
            requestLogger.ExcludeRequestDtoTypes            = ExcludeRequestDtoTypes.ToArray();
            requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes.ToArray();

            appHost.Register(requestLogger);
        }
Exemple #3
0
 protected bool ExcludeRequestType(Type requestType)
 {
     return(ExcludeRequestDtoTypes != null &&
            requestType != null &&
            ExcludeRequestDtoTypes.Contains(requestType));
 }
Exemple #4
0
        public void Log(IRequest request, object requestDto, object response, TimeSpan requestDuration)
        {
            var requestType = requestDto != null?requestDto.GetType() : null;

            if (ExcludeRequestDtoTypes != null &&
                requestType != null &&
                ExcludeRequestDtoTypes.Contains(requestType))
            {
                return;
            }

            var entry = new RequestLogEntry {
                Id              = Interlocked.Increment(ref requestId),
                DateTime        = DateTime.UtcNow,
                RequestDuration = requestDuration,
            };

            if (request != null)
            {
                entry.HttpMethod   = request.Verb;
                entry.AbsoluteUri  = request.AbsoluteUri;
                entry.PathInfo     = request.PathInfo;
                entry.IpAddress    = request.UserHostAddress;
                entry.ForwardedFor = request.Headers[HttpHeaders.XForwardedFor];
                entry.Referer      = request.Headers[HttpHeaders.Referer];
                entry.Headers      = request.Headers.ToDictionary();
                entry.UserAuthId   = request.GetItemOrCookie(HttpHeaders.XUserAuthId);
                entry.SessionId    = request.GetSessionId();
                entry.Items        = SerializableItems(request.Items);
                entry.Session      = EnableSessionTracking ? request.GetSession() : null;
                new NameValueCollection().ToDictionary();
            }

            if (HideRequestBodyForRequestDtoTypes != null &&
                requestType != null &&
                !HideRequestBodyForRequestDtoTypes.Contains(requestType))
            {
                entry.RequestDto = requestDto;
                if (request != null)
                {
                    entry.FormData = request.FormData.ToDictionary();

                    if (EnableRequestBodyTracking)
                    {
                        entry.RequestBody = request.GetRawBody();
                    }
                }
            }
            if (!response.IsErrorResponse())
            {
                if (EnableResponseTracking)
                {
                    entry.ResponseDto = response;
                }
            }
            else
            {
                if (EnableErrorTracking)
                {
                    entry.ErrorResponse = ToSerializableErrorResponse(response);
                }
            }

            logEntries.Enqueue(entry);

            RequestLogEntry dummy;

            if (logEntries.Count > capacity)
            {
                logEntries.TryDequeue(out dummy);
            }
        }