Rock.Model.ExceptionLogService.LogException C# (CSharp) Method

LogException() public static method

Logs new Rock.Model.ExceptionLog entities. This method serves as an interface to asynchronously log exceptions.
public static LogException ( Exception ex, HttpContext context, int pageId = null, int siteId = null, PersonAlias personAlias = null ) : void
ex System.Exception A object to log.
context System.Web.HttpContext The
pageId int A containing the Id of the that the exception occurred on. /// This parameter is nullable..
siteId int A containing the Id of the that the exception occurred on.
personAlias PersonAlias The person alias.
return void
        public static void LogException( Exception ex, HttpContext context, int? pageId = null, int? siteId = null, PersonAlias personAlias = null )
        {
            // Populate the initial ExceptionLog with data from HttpContext. Must capture initial
            // HttpContext details before spinning off new thread, because the current context will
            // not be the same within the context of the new thread.
            var exceptionLog = PopulateExceptionLog( ex, context, pageId, siteId, personAlias );

            // Spin off a new thread to handle the real logging work so the UI is not blocked whilst
            // recursively writing to the database.
            Task.Run( () => LogExceptions( ex, exceptionLog, true ) );
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Gets the Linq expression for the DataViewFilter.
        /// </summary>
        /// <param name="filteredEntityType">The object type of the filtered entity.</param>
        /// <param name="serviceInstance">A <see cref="System.Object"/> that contains the service reference.</param>
        /// <param name="parameter">A <see cref="System.Linq.Expressions.ParameterExpression"/> containing the parameter for the expression.</param>
        /// <param name="errorMessages">A <see cref="System.Collections.Generic.List{String}"/> that contains any error/exception messages that are returned.</param>
        /// <returns></returns>
        public virtual Expression GetExpression(Type filteredEntityType, IService serviceInstance, ParameterExpression parameter, List <string> errorMessages)
        {
            switch (ExpressionType)
            {
            case FilterExpressionType.Filter:

                if (this.EntityTypeId.HasValue)
                {
                    var entityType = Rock.Web.Cache.EntityTypeCache.Read(this.EntityTypeId.Value);
                    if (entityType != null)
                    {
                        var component = Rock.Reporting.DataFilterContainer.GetComponent(entityType.Name);
                        if (component != null)
                        {
                            try
                            {
                                return(component.GetExpression(filteredEntityType, serviceInstance, parameter, this.Selection));
                            }
                            catch (SystemException ex)
                            {
                                ExceptionLogService.LogException(ex, System.Web.HttpContext.Current);
                                errorMessages.Add(string.Format("{0}: {1}", component.FormatSelection(filteredEntityType, this.Selection), ex.Message));
                            }
                        }
                    }
                }
                return(null);

            case FilterExpressionType.GroupAll:
            case FilterExpressionType.GroupAnyFalse:

                Expression andExp = null;
                foreach (var filter in this.ChildFilters)
                {
                    Expression exp = filter.GetExpression(filteredEntityType, serviceInstance, parameter, errorMessages);
                    if (exp != null)
                    {
                        if (andExp == null)
                        {
                            andExp = exp;
                        }
                        else
                        {
                            andExp = Expression.AndAlso(andExp, exp);
                        }
                    }
                }

                if (ExpressionType == FilterExpressionType.GroupAnyFalse &&
                    andExp != null)
                {
                    // If only one of the conditions must be false, invert the expression so that it becomes the logical equivalent of "NOT ALL".
                    andExp = Expression.Not(andExp);
                }

                return(andExp);

            case FilterExpressionType.GroupAny:
            case FilterExpressionType.GroupAllFalse:

                Expression orExp = null;
                foreach (var filter in this.ChildFilters)
                {
                    Expression exp = filter.GetExpression(filteredEntityType, serviceInstance, parameter, errorMessages);
                    if (exp != null)
                    {
                        if (orExp == null)
                        {
                            orExp = exp;
                        }
                        else
                        {
                            orExp = Expression.OrElse(orExp, exp);
                        }
                    }
                }

                if (ExpressionType == FilterExpressionType.GroupAllFalse &&
                    orExp != null)
                {
                    // If all of the conditions must be false, invert the expression so that it becomes the logical equivalent of "NOT ANY".
                    orExp = Expression.Not(orExp);
                }

                return(orExp);
            }

            return(null);
        }
All Usage Examples Of Rock.Model.ExceptionLogService::LogException