/// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public virtual void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            if (exception == null)
            {
                throw new ArgumentNullException(nameof(propertiesBag));
            }

            if (propertiesBag == null)
            {
                throw new ArgumentNullException(nameof(propertiesBag));
            }

            if (destructureException == null)
            {
                throw new ArgumentNullException(nameof(destructureException));
            }

            propertiesBag.AddProperty("Type", exception.GetType().FullName);

            DestructureCommonExceptionProperties(
                exception,
                propertiesBag,
                destructureException,
                data => data.ToStringObjectDictionary());
        }
 public override void Destructure(
     Exception exception,
     IExceptionPropertiesBag propertiesBag,
     Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
 {
     base.Destructure(exception, propertiesBag, destructureException);
 }
        /// <inheritdoc />
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var dbUpdateException = (DbUpdateException)exception;
            var entriesValue      = dbUpdateException.Entries?
                                    .Select(
                e => new
            {
                EntryProperties = e.Properties.Select(
                    p => new
                {
                    PropertyName = p.Metadata.Name,
                    p.OriginalValue,
                    p.CurrentValue,
                    p.IsTemporary,
                    p.IsModified,
                }),
                e.State,
            })
                                    .ToList();
            propertiesBag.AddProperty(nameof(DbUpdateException.Entries), entriesValue);
#pragma warning restore CA1062 // Validate arguments of public methods
        }
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            var nextCyclicRefId     = 1;
            var destructuredObjects = new Dictionary <object, IDictionary <string, object> >();

            ExceptionDestructurer.DestructureCommonExceptionProperties(
                exception,
                propertiesBag,
                destructureException,
                data => this.DestructureValueDictionary(data, 1, destructuredObjects, ref nextCyclicRefId));

            var reflectionInfo = this.GetOrCreateReflectionInfo(exception.GetType());

            this.AppendProperties(
                exception,
                reflectionInfo.PropertiesExceptBaseOnes,
                propertiesBag.AddProperty,
                destructuredObjects,
                level: 0,
                nextCyclicRefId: ref nextCyclicRefId);

            this.AppendTypeIfPossible(propertiesBag, exception.GetType());
        }
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

            var argumentException = (ArgumentException)exception;

            propertiesBag.AddProperty(nameof(ArgumentException.ParamName), argumentException.ParamName);
        }
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var argumentException = (ArgumentException)exception;
            propertiesBag.AddProperty(nameof(ArgumentException.ParamName), argumentException.ParamName);
#pragma warning restore CA1062 // Validate arguments of public methods
        }
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public virtual void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > innerDestructure)
        {
            propertiesBag.AddProperty("Type", exception.GetType().FullName);

            DestructureCommonExceptionProperties(
                exception,
                propertiesBag,
                innerDestructure,
                data => data.ToStringObjectDictionary());
        }
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

            var aggregateException = (AggregateException)exception;

            propertiesBag.AddProperty(
                nameof(AggregateException.InnerExceptions),
                aggregateException.InnerExceptions.Select(destructureException).ToList());
        }
示例#9
0
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
#pragma warning disable CA1062 // Validate arguments of public methods
            base.Destructure(exception, propertiesBag, destructureException);

            var taskCancelledException = (TaskCanceledException)exception;
            propertiesBag.AddProperty(
                nameof(TaskCanceledException.Task),
                DestructureTask(taskCancelledException.Task, destructureException));
#pragma warning restore CA1062 // Validate arguments of public methods
        }
示例#10
0
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var operationCancelledException = (OperationCanceledException)exception;
            propertiesBag.AddProperty(
                nameof(OperationCanceledException.CancellationToken),
                DestructureCancellationToken(operationCancelledException.CancellationToken));
#pragma warning restore CA1062 // Validate arguments of public methods
        }
示例#11
0
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var aggregateException = (AggregateException)exception;
            propertiesBag.AddProperty(
                nameof(AggregateException.InnerExceptions),
                aggregateException.InnerExceptions.Select(destructureException).ToList());
#pragma warning restore CA1062 // Validate arguments of public methods
        }
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);
            BenchmarkException benchmarkException = (BenchmarkException)exception;

            propertiesBag.AddProperty("ParamString", benchmarkException.ParamString);
            propertiesBag.AddProperty("ParamInt", benchmarkException.ParamInt);
            propertiesBag.AddProperty("Point", new Dictionary <string, object>
            {
                { "X", benchmarkException.Point.X },
                { "Y", benchmarkException.Point.Y }
            });
        }
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

            var reflectionTypeLoadException = (ReflectionTypeLoadException)exception;

            if (reflectionTypeLoadException.LoaderExceptions != null)
            {
                propertiesBag.AddProperty(
                    nameof(ReflectionTypeLoadException.LoaderExceptions),
                    reflectionTypeLoadException.LoaderExceptions.Select(destructureException).ToList());
            }
        }
示例#14
0
        public override void Destructure(Exception exception,
                                         IExceptionPropertiesBag propertiesBag,
                                         Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

            var sqlException = (SqlException)exception;

            propertiesBag.AddProperty(nameof(SqlException.ClientConnectionId), sqlException.ClientConnectionId);
            propertiesBag.AddProperty(nameof(SqlException.Class), sqlException.Class);
            propertiesBag.AddProperty(nameof(SqlException.LineNumber), sqlException.LineNumber);
            propertiesBag.AddProperty(nameof(SqlException.Number), sqlException.Number);
            propertiesBag.AddProperty(nameof(SqlException.Server), sqlException.Server);
            propertiesBag.AddProperty(nameof(SqlException.State), sqlException.State);
            propertiesBag.AddProperty(nameof(SqlException.Errors), sqlException.Errors.Cast <SqlError>().ToArray());
        }
示例#15
0
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var socketException = (SocketException)exception;
            propertiesBag.AddProperty(nameof(SocketException.SocketErrorCode), socketException.SocketErrorCode);
            if (SocketErrorDocumentationBySocketError.TryGetValue(socketException.SocketErrorCode, out var documentation))
            {
                propertiesBag.AddProperty(nameof(SocketException.SocketErrorCode) + "Message", documentation);
            }
#pragma warning restore CA1062 // Validate arguments of public methods
        }
示例#16
0
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var reflectionTypeLoadException = (ReflectionTypeLoadException)exception;
            if (reflectionTypeLoadException.LoaderExceptions is object)
            {
                propertiesBag.AddProperty(
                    nameof(ReflectionTypeLoadException.LoaderExceptions),
                    reflectionTypeLoadException.LoaderExceptions.Select(destructureException).ToList());
            }
#pragma warning restore CA1062 // Validate arguments of public methods
        }
        /// <inheritdoc />
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var sqlException = (SqlException)exception;
            propertiesBag.AddProperty(nameof(SqlException.ClientConnectionId), sqlException.ClientConnectionId);
            propertiesBag.AddProperty(nameof(SqlException.Class), sqlException.Class);
            propertiesBag.AddProperty(nameof(SqlException.LineNumber), sqlException.LineNumber);
            propertiesBag.AddProperty(nameof(SqlException.Number), sqlException.Number);
            propertiesBag.AddProperty(nameof(SqlException.Server), sqlException.Server);
            propertiesBag.AddProperty(nameof(SqlException.State), sqlException.State);
            propertiesBag.AddProperty(nameof(SqlException.Errors), sqlException.Errors.Cast <SqlError>().ToArray());
#pragma warning restore CA1062 // Validate arguments of public methods
        }
        /// <inheritdoc />
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

#pragma warning disable CA1062 // Validate arguments of public methods
            var benchmarkException = (BenchmarkException)exception;
            propertiesBag.AddProperty("ParamString", benchmarkException.ParamString);
            propertiesBag.AddProperty("ParamInt", benchmarkException.ParamInt);
            propertiesBag.AddProperty("Point", new Dictionary <string, object>
            {
                { "X", benchmarkException.Point.X },
                { "Y", benchmarkException.Point.Y },
            });
#pragma warning restore CA1062 // Validate arguments of public methods
        }
示例#19
0
 private void AppendTypeIfPossible(IExceptionPropertiesBag propertiesBag, Type valueType)
 {
     if (propertiesBag.ContainsProperty("Type"))
     {
         if (!propertiesBag.ContainsProperty("$Type"))
         {
             propertiesBag.AddProperty("$Type", valueType.FullName);
         }
         else
         {
             // If both "Type" and "$Type" are present
             // we just give up appending exception type
         }
     }
     else
     {
         propertiesBag.AddProperty("Type", valueType.FullName);
     }
 }
示例#20
0
        /// <inheritdoc cref="IExceptionDestructurer.Destructure"/>
        public override void Destructure(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > destructureException)
        {
            base.Destructure(exception, propertiesBag, destructureException);

            DbEntityValidationException validationException = exception as DbEntityValidationException;

            if (validationException is null)
            {
                return;
            }

            foreach (var error in validationException.EntityValidationErrors)
            {
                foreach (var ve in error.ValidationErrors)
                {
                    propertiesBag.AddProperty(ve.PropertyName, ve.ErrorMessage);
                }
            }
        }
        /// <summary>
        /// Destructures public properties of <see cref="Exception"/>.
        /// Omits less frequently used ones if they are null.
        /// </summary>
        /// <param name="exception">The exception that will be destructured.</param>
        /// <param name="propertiesBag">The bag when destructured properties will be put.</param>
        /// <param name="innerDestructure">Function that can be used to destructure inner exceptions if there are any.</param>
        /// <param name="destructureDataProperty">Injected function for destructuring <see cref="Exception.Data"/>.</param>
        internal static void DestructureCommonExceptionProperties(
            Exception exception,
            IExceptionPropertiesBag propertiesBag,
            Func <Exception, IReadOnlyDictionary <string, object> > innerDestructure,
            Func <System.Collections.IDictionary, object> destructureDataProperty)
        {
            if (exception.Data.Count != 0)
            {
                propertiesBag.AddProperty(nameof(Exception.Data), destructureDataProperty(exception.Data));
            }

            if (!string.IsNullOrEmpty(exception.HelpLink))
            {
                propertiesBag.AddProperty(nameof(Exception.HelpLink), exception.HelpLink);
            }

            if (exception.HResult != 0)
            {
                propertiesBag.AddProperty(nameof(Exception.HResult), exception.HResult);
            }

            propertiesBag.AddProperty(nameof(Exception.Message), exception.Message);
            propertiesBag.AddProperty(nameof(Exception.Source), exception.Source);
            propertiesBag.AddProperty(nameof(Exception.StackTrace), exception.StackTrace);

#if NET461 || NET472
            if (exception.TargetSite != null)
            {
                propertiesBag.AddProperty(nameof(Exception.TargetSite), exception.TargetSite.ToString());
            }
#endif

            if (exception.InnerException != null)
            {
                propertiesBag.AddProperty(nameof(Exception.InnerException), innerDestructure(exception.InnerException));
            }
        }