public static SimpleError ToSimpleErrorModel(this Exception exception) { Type type = exception.GetType(); var error = new SimpleError { Message = GetMessage(exception), Type = type.FullName, StackTrace = exception.StackTrace }; 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(SimpleError.KnownDataKeys.ExtraProperties)) { error.AddObject(new ExtendedDataInfo { Data = extraProperties, Name = SimpleError.KnownDataKeys.ExtraProperties, IgnoreSerializationErrors = true, MaxDepthToSerialize = 5 }); } } catch {} if (exception.InnerException != null) error.Inner = exception.InnerException.ToSimpleErrorModel(); return error; }
/// <summary> /// Sets the properties from an exception. /// </summary> /// <param name="exception">The exception to populate properties from.</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Default. /// </param> public static SimpleError ToSimpleErrorModel(this Exception exception, ExceptionlessClient client = null) { if (client == null) client = ExceptionlessClient.Default; var log = client.Configuration.Resolver.GetLog(); Type type = exception.GetType(); var error = new SimpleError { Message = GetMessage(exception), Type = type.FullName, StackTrace = exception.StackTrace }; 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(SimpleError.KnownDataKeys.ExtraProperties)) { error.AddObject(new ExtendedDataInfo { Data = extraProperties, Name = SimpleError.KnownDataKeys.ExtraProperties, IgnoreSerializationErrors = true, MaxDepthToSerialize = 5 }, client); } } catch {} if (exception.InnerException != null) error.Inner = exception.InnerException.ToSimpleErrorModel(client); return error; }
/// <summary> /// Sets the properties from an exception. /// </summary> /// <param name="exception">The exception to populate properties from.</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Default. /// </param> public static SimpleError ToSimpleErrorModel(this Exception exception, ExceptionlessClient client = null) { if (client == null) client = ExceptionlessClient.Default; Type type = exception.GetType(); var error = new SimpleError { Message = GetMessage(exception), Type = type.FullName, StackTrace = exception.StackTrace }; 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(SimpleError.KnownDataKeys.ExtraProperties)) { error.AddObject(new ExtendedDataInfo { Data = extraProperties, Name = SimpleError.KnownDataKeys.ExtraProperties, IgnoreSerializationErrors = true, MaxDepthToSerialize = 5 }, client); } } catch {} if (exception.InnerException != null) error.Inner = exception.InnerException.ToSimpleErrorModel(client); return error; }
protected bool Equals(SimpleError other) { return string.Equals(Message, other.Message) && string.Equals(Type, other.Type) && string.Equals(StackTrace, other.StackTrace) && Equals(Data, other.Data) && Equals(Inner, other.Inner); }
public SimpleError GenerateSimpleError(int maxErrorNestingLevel = 3, bool generateData = true, int currentNestingLevel = 0) { var error = new SimpleError { Message = @"Generated exception message.", Type = ExceptionTypes.Random() }; if (generateData) { for (int i = 0; i < RandomData.GetInt(1, 5); i++) { string key = RandomData.GetWord(); while (error.Data.ContainsKey(key) || key == Event.KnownDataKeys.Error) key = RandomData.GetWord(); error.Data.Add(key, RandomData.GetString()); } } error.StackTrace = RandomData.GetString(); if (currentNestingLevel < maxErrorNestingLevel && RandomData.GetBool()) error.Inner = GenerateSimpleError(maxErrorNestingLevel, generateData, currentNestingLevel + 1); return error; }
protected bool Equals(SimpleError other) { return(base.Equals(other) && Modules.CollectionEquals(other.Modules)); }
protected bool Equals(SimpleError other) { return(string.Equals(Message, other.Message) && string.Equals(Type, other.Type) && string.Equals(StackTrace, other.StackTrace) && Equals(Data, other.Data) && Equals(Inner, other.Inner)); }