Exemple #1
0
        /// <summary>Creates a new instance of <see cref="Error" />.</summary>
        /// <param name="ex">An <see cref="Exception" /> to initialize the <see cref="Error" /> with.</param>
        /// <param name="isCritical">Mark this error occurrence as a critical error.</param>
        /// <param name="addDefaultInformation">
        /// Whether to add the default information like request info and machine info to the
        /// case or not.
        /// </param>
        /// <param name="extendedData">
        /// As list of objects to add to the error's ExtendedData collection. If the object is an
        /// <see cref="ExtendedDataInfo">ExtendedDataInfo</see>, the settings from that will be used to add the ExtendedData.
        /// </param>
        /// <param name="tags">A list of tags to add to the error.</param>
        /// <param name="submissionMethod">The method that was used to collect the error.</param>
        /// <param name="contextData">Any additional contextual data that should be used during creation of the error information.</param>
        /// <returns>A new instance of <see cref="Error" />.</returns>
        public Error CreateError(Exception ex, bool isCritical = false, bool addDefaultInformation = true, IEnumerable <object> extendedData = null, IEnumerable <string> tags = null, string submissionMethod = "Manual", IDictionary <string, object> contextData = null)
        {
            Error error = ToError(this, ex, submissionMethod, contextData);

            if (extendedData != null)
            {
                foreach (object o in extendedData)
                {
                    error.AddObject(o);
                }
            }

            if (tags != null)
            {
                error.Tags.AddRange(tags);
            }

            if (isCritical)
            {
                error.MarkAsCritical();
            }

            if (addDefaultInformation)
            {
                error.AddDefaultInformation(contextData);
            }

            return(error);
        }
Exemple #2
0
        private static Error ToErrorModelInternal(Exception exception, IExceptionlessLog log, bool isInner = false)
        {
            Type type = exception.GetType();

            var error = new Error {
                Message = exception.GetMessage(),
                Type    = type.FullName
            };

            if (!isInner)
            {
                error.Modules = GetLoadedModules(log);
            }

            error.PopulateStackTrace(error, exception);

            try {
                PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
                if (info != null)
                {
                    error.Code = info.GetValue(exception, null).ToString();
                }
            } catch (Exception) { }

            if (exception.TargetSite != null)
            {
                error.TargetMethod = new Method();
                error.TargetMethod.PopulateMethod(error, exception.TargetSite);
            }

            try {
                Dictionary <string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
                    try {
                        return(p.GetValue(exception, null));
                    } catch { }
                    return(null);
                });

                extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties))
                {
                    error.AddObject(new ExtendedDataInfo {
                        Data = extraProperties,
                        Name = Error.KnownDataKeys.ExtraProperties,
                        IgnoreSerializationErrors = true,
                        MaxDepthToSerialize       = 5
                    });
                }
            } catch { }

            if (exception.InnerException != null)
            {
                error.Inner = ToErrorModelInternal(exception.InnerException, log, true);
            }

            return(error);
        }
        /// <summary>
        /// Sets the properties from an exception.
        /// </summary>
        /// <param name="exception">The exception to populate properties from.</param>
        /// <param name="log">The log implementation used for diagnostic information.</param>
        public static Error ToErrorModel(this Exception exception, IExceptionlessLog log) {
            Type type = exception.GetType();

            var error = new Error {
                Message = exception.GetMessage(),
                Modules = GetLoadedModules(log),
                Type = type.FullName
            };
            error.PopulateStackTrace(error, exception);

            try {
                PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
                if (info != null)
                    error.Code = info.GetValue(exception, null).ToString();
            } catch (Exception) {}

            if (exception.TargetSite != null) {
                error.TargetMethod = new Method();
                error.TargetMethod.PopulateMethod(error, exception.TargetSite);
            }

            // TODO: Test adding non-serializable objects to ExtendedData and see what happens
            try {
                Dictionary<string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
                    try {
                        return p.GetValue(exception, null);
                    } catch {}
                    return null;
                });

                extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)) {
                    error.AddObject(new ExtendedDataInfo {
                        Data = extraProperties,
                        Name = Error.KnownDataKeys.ExtraProperties,
                        IgnoreSerializationErrors = true,
                        MaxDepthToSerialize = 5
                    });
                }
            } catch {}

            if (exception.InnerException != null)
                error.Inner = exception.InnerException.ToErrorModel(log);

            return error;
        }
Exemple #4
0
        private static Error ToErrorModelInternal(Exception exception, ExceptionlessClient client, bool isInner = false)
        {
            var  log  = client.Configuration.Resolver.GetLog();
            Type type = exception.GetType();

            var error = new Error {
                Message = exception.GetMessage(),
                Type    = type.FullName
            };

            if (!isInner)
            {
                error.Modules = GetLoadedModules(log);
            }

            error.PopulateStackTrace(error, exception, log);

            try {
                PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
                if (info != null)
                {
                    error.Code = info.GetValue(exception, null).ToString();
                }
            } catch (Exception) { }

#if NET45
            try {
                if (exception.TargetSite != null)
                {
                    error.TargetMethod = new Method();
                    error.TargetMethod.PopulateMethod(error, exception.TargetSite);
                }
            } catch (Exception ex) {
                log.Error(typeof(ExceptionlessClient), ex, "Error populating TargetMethod: " + ex.Message);
            }
#endif

            var exclusions = _exceptionExclusions.Union(client.Configuration.DataExclusions).ToList();
            try {
                if (exception.Data != null)
                {
                    foreach (object k in exception.Data.Keys)
                    {
                        string key = k != null?k.ToString() : null;

                        if (String.IsNullOrEmpty(key) || key.AnyWildcardMatches(exclusions, true))
                        {
                            continue;
                        }

                        var item = exception.Data[k];
                        if (item == null)
                        {
                            continue;
                        }

                        error.Data[key] = item;
                    }
                }
            } catch (Exception ex) {
                log.Error(typeof(ExceptionlessClient), ex, "Error populating Data: " + ex.Message);
            }

            try {
                var extraProperties = type.GetPublicProperties().Where(p => !p.Name.AnyWildcardMatches(exclusions, true)).ToDictionary(p => p.Name, p => {
                    try {
                        return(p.GetValue(exception, null));
                    } catch { }
                    return(null);
                });

                extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties))
                {
                    error.AddObject(new ExtendedDataInfo {
                        Data = extraProperties,
                        Name = Error.KnownDataKeys.ExtraProperties,
                        IgnoreSerializationErrors = true,
                        MaxDepthToSerialize       = 5
                    }, client);
                }
            } catch { }

            if (exception.InnerException != null)
            {
                error.Inner = ToErrorModelInternal(exception.InnerException, client, true);
            }

            return(error);
        }
Exemple #5
0
        /// <summary>
        /// Sets the properties from an exception.
        /// </summary>
        /// <param name="exception">The exception to populate properties from.</param>
        /// <param name="log">The log implementation used for diagnostic information.</param>
        public static Error ToErrorModel(this Exception exception
#if EMBEDDED
                                         , IExceptionlessLog log = null
#endif
                                         )
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

#if EMBEDDED
            if (log == null)
            {
                log = new NullExceptionlessLog();
            }
#endif

            Type type = exception.GetType();

            var error = new Error {
                Message = exception.GetMessage(),
#if EMBEDDED
                Modules = GetLoadedModules(log),
#else
                Modules = GetLoadedModules(),
#endif
                Type = type.FullName
            };
            error.PopulateStackTrace(error, exception);

#if !SILVERLIGHT
            try {
                PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
                if (info != null)
                {
                    error.Code = info.GetValue(exception, null).ToString();
                }
            } catch (Exception) {}
#endif

            if (exception.TargetSite != null)
            {
                error.TargetMethod = new Method();
                error.TargetMethod.PopulateMethod(error, exception.TargetSite);
            }

            // TODO: Test adding non-serializable objects to ExtendedData and see what happens
            try {
                Dictionary <string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
                    try {
                        return(p.GetValue(exception, null));
                    } catch {}
                    return(null);
                });

                extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (extraProperties.Count > 0 && !error.ExtendedData.ContainsKey(ExtendedDataDictionary.EXCEPTION_INFO_KEY))
                {
                    error.AddObject(new ExtendedDataInfo {
                        Data = extraProperties,
                        Name = ExtendedDataDictionary.EXCEPTION_INFO_KEY,
                        IgnoreSerializationErrors = true,
                        MaxDepthToSerialize       = 5
                    });
                }
            } catch {}

            if (exception.InnerException != null)
            {
                error.Inner = exception.InnerException.ToErrorModel();
            }

            return(error);
        }
        private static Error ToErrorModelInternal(Exception exception, ExceptionlessClient client, bool isInner = false) {
            var log = client.Configuration.Resolver.GetLog();
            Type type = exception.GetType();

            var error = new Error {
                Message = exception.GetMessage(),
                Type = type.FullName
            };

            if (!isInner)
                error.Modules = GetLoadedModules(log);

            error.PopulateStackTrace(error, exception, log);

            try {
                PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
                if (info != null)
                    error.Code = info.GetValue(exception, null).ToString();
            } catch (Exception) { }

            try {
                if (exception.TargetSite != null) {
                    error.TargetMethod = new Method();
                    error.TargetMethod.PopulateMethod(error, exception.TargetSite);
                }
            } catch (Exception ex) {
                log.Error(typeof(ExceptionlessClient), ex, "Error populating TargetMethod: " + ex.Message);
            }

            try {
                var exclusions = _exceptionExclusions.Union(client.Configuration.DataExclusions);
                var extraProperties = type.GetPublicProperties().Where(p => !p.Name.AnyWildcardMatches(exclusions, true)).ToDictionary(p => p.Name, p => {
                    try {
                        return p.GetValue(exception, null);
                    } catch { }
                    return null;
                });

                extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)) {
                    error.AddObject(new ExtendedDataInfo {
                        Data = extraProperties,
                        Name = Error.KnownDataKeys.ExtraProperties,
                        IgnoreSerializationErrors = true,
                        MaxDepthToSerialize = 5
                    }, client);
                }
            } catch { }

            if (exception.InnerException != null)
                error.Inner = ToErrorModelInternal(exception.InnerException, client, true);

            return error;
        }
        /// <summary>
        /// Sets the properties from an exception.
        /// </summary>
        /// <param name="exception">The exception to populate properties from.</param>
        /// <param name="log">The log implementation used for diagnostic information.</param>
        public static Error ToErrorModel(this Exception exception
#if EMBEDDED
            , IExceptionlessLog log = null
#endif
            ) {
            if (exception == null)
                throw new ArgumentNullException("exception");

#if EMBEDDED
            if (log == null)
                log = new NullExceptionlessLog();
#endif

            Type type = exception.GetType();

            var error = new Error {
                Message = exception.GetMessage(),
#if EMBEDDED
                Modules = GetLoadedModules(log),
#else
                Modules = GetLoadedModules(),
#endif
                Type = type.FullName
            };
            error.PopulateStackTrace(error, exception);

#if !SILVERLIGHT
            try {
                PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
                if (info != null)
                    error.Code = info.GetValue(exception, null).ToString();
            } catch (Exception) {}
#endif

            if (exception.TargetSite != null) {
                error.TargetMethod = new Method();
                error.TargetMethod.PopulateMethod(error, exception.TargetSite);
            }

            // TODO: Test adding non-serializable objects to ExtendedData and see what happens
            try {
                Dictionary<string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
                    try {
                        return p.GetValue(exception, null);
                    } catch {}
                    return null;
                });

                extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (extraProperties.Count > 0 && !error.ExtendedData.ContainsKey(ExtendedDataDictionary.EXCEPTION_INFO_KEY)) {
                    error.AddObject(new ExtendedDataInfo {
                        Data = extraProperties,
                        Name = ExtendedDataDictionary.EXCEPTION_INFO_KEY,
                        IgnoreSerializationErrors = true,
                        MaxDepthToSerialize = 5
                    });
                }
            } catch {}

            if (exception.InnerException != null)
                error.Inner = exception.InnerException.ToErrorModel();

            return error;
        }