예제 #1
0
        public static IEnumerable<FailOccurrenceDto> Dequeue(int count)
        {
            try
            {
                _queueLock.EnterWriteLock();

                var returnCount = Math.Min(count, _failQueue.Count);
                var fails = new FailOccurrenceDto[returnCount];

                for (var i = 0; i < returnCount; i++)
                {
                    fails[i] = _failQueue.Dequeue();
                }

                // if the queue holds less than the batch size, reset the queue signal
                if (_failQueue.Count < ConfigurationModel.Instance.ReportingMinimumBatchSize)
                {
                    _queueSignal.Reset();
                }

                return fails;
            }
            finally
            {
                _queueLock.ExitWriteLock();
            }
        }
예제 #2
0
        public static void Enqueue(FailOccurrenceDto failReport)
        {
            // When recording a new fail report, make sure that the reporting worker is running
            ReportingWorker.Instance.Start();

            try
            {
                _queueLock.EnterWriteLock();
                _failQueue.Enqueue(failReport);
                
                // Signal that the queue is at least at the minimum batch size
                if (_failQueue.Count >= ConfigurationModel.Instance.ReportingMinimumBatchSize)
                {
                    _queueSignal.Set();
                }
            }
            finally
            {
                _queueLock.ExitWriteLock();
            }
        }
        internal static FailOccurrenceDto FromException(HttpContextBase httpContext, Exception e)
        {
            var baseException = e.GetBaseException();

            var request = httpContext.Request;
            var urlReferrer = request.UrlReferrer != null ? request.UrlReferrer.ToString() : null;

            var requestUrl = request.Url != null ? request.Url.ToString() : null;
            
            string user = null;

            if (ConfigurationModel.Instance.ReportCurrentUsername)
            {
                if (ConfigurationModel.Instance.PopulateUsernameFrom != null)
                {
                    user = ConfigurationModel.Instance.PopulateUsernameFrom();
                }
                else if (httpContext.User != null && httpContext.User.Identity != null)
                {
                    user = httpContext.User.Identity.Name;
                }
            }
            
            string machineName = GetMachineName(httpContext);

            // Filter query & post value pairs according to locally defined rules
            string[][] postValuePairs = null;
            string[][] queryValuePairs = null;
            string[][] serverVariables = null;
            string[][] cookies = null;

            try
            {
                queryValuePairs = CreateCopy(request.QueryString, x => Appfail.IsPostFiltered(x));
                postValuePairs = CreateCopy(request.Form, x => Appfail.IsPostFiltered(x));
                serverVariables = CreateCopy(request.ServerVariables, x => Appfail.IsServerVariableFiltered(x));
                cookies = CreateCopy(request.Cookies, x => Appfail.IsCookieFiltered(x));
            }
            catch (HttpRequestValidationException)
            {}

            var httpException = e as HttpException;
            
            // Report all exceptions, starting from the top and moving toward the base exception
            var allExceptions = new List<ExceptionDto>();

            var nextException = e;

            while (nextException != null)
            {
                allExceptions.Insert(0, new ExceptionDto(nextException.StackTrace, nextException.Message, nextException.GetType().FullName));
                nextException = nextException.InnerException;
            }

            var report = new FailOccurrenceDto(allExceptions.ToArray(),
                                            requestUrl,
                                            request.HttpMethod,
                                            urlReferrer,
                                            DateTime.UtcNow,
                                            user,
                                            postValuePairs,
                                            queryValuePairs,
                                            request.UserAgent,
                                            serverVariables,
                                            cookies,
                                            machineName,
                                            
                                            httpException != null ? httpException.GetHttpCode() : (int?)null);

            return report;
        }
        internal static FailOccurrenceDto FromException(HttpContextBase httpContext, Exception e)
        {
            var baseException = e.GetBaseException();

            var request     = httpContext.Request;
            var urlReferrer = request.UrlReferrer != null?request.UrlReferrer.ToString() : null;

            var requestUrl = request.Url != null?request.Url.ToString() : null;

            string user = null;

            if (ConfigurationModel.Instance.ReportCurrentUsername)
            {
                if (ConfigurationModel.Instance.PopulateUsernameFrom != null)
                {
                    user = ConfigurationModel.Instance.PopulateUsernameFrom();
                }
                else if (httpContext.User != null && httpContext.User.Identity != null)
                {
                    user = httpContext.User.Identity.Name;
                }
            }

            string machineName = GetMachineName(httpContext);

            // Filter query & post value pairs according to locally defined rules
            string[][] postValuePairs  = null;
            string[][] queryValuePairs = null;
            string[][] serverVariables = null;
            string[][] cookies         = null;

            try
            {
                queryValuePairs = CreateCopy(request.QueryString, x => Appfail.IsPostFiltered(x));
                postValuePairs  = CreateCopy(request.Form, x => Appfail.IsPostFiltered(x));
                serverVariables = CreateCopy(request.ServerVariables, x => Appfail.IsServerVariableFiltered(x));
                cookies         = CreateCopy(request.Cookies, x => Appfail.IsCookieFiltered(x));
            }
            catch (HttpRequestValidationException)
            {}

            var httpException = e as HttpException;

            // Report all exceptions, starting from the top and moving toward the base exception
            var allExceptions = new List <ExceptionDto>();

            var nextException = e;

            while (nextException != null)
            {
                allExceptions.Insert(0, new ExceptionDto(nextException.StackTrace, nextException.Message, nextException.GetType().FullName));
                nextException = nextException.InnerException;
            }

            var report = new FailOccurrenceDto(allExceptions.ToArray(),
                                               requestUrl,
                                               request.HttpMethod,
                                               urlReferrer,
                                               DateTime.UtcNow,
                                               user,
                                               postValuePairs,
                                               queryValuePairs,
                                               request.UserAgent,
                                               serverVariables,
                                               cookies,
                                               machineName,

                                               httpException != null ? httpException.GetHttpCode() : (int?)null);

            return(report);
        }