当前位置: 首页>>代码示例>>C#>>正文


C# Error.PopulateStackTrace方法代码示例

本文整理汇总了C#中Error.PopulateStackTrace方法的典型用法代码示例。如果您正苦于以下问题:C# Error.PopulateStackTrace方法的具体用法?C# Error.PopulateStackTrace怎么用?C# Error.PopulateStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Error的用法示例。


在下文中一共展示了Error.PopulateStackTrace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToErrorModelInternal

        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;
        }
开发者ID:Xamarui,项目名称:Exceptionless.Net,代码行数:55,代码来源:ToErrorModelExtensions.cs

示例2: ToErrorModel

        /// <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;
        }
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:52,代码来源:ToErrorModelExtensions.cs

示例3: ToErrorModel

        /// <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;
        }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:70,代码来源:ToErrorModelExtensions.cs


注:本文中的Error.PopulateStackTrace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。