/// <summary> /// Adds the object to extended data. /// </summary> /// <param name="error">The error.</param> /// <param name="data">The data object to add.</param> /// <param name="name">The name of the object to add.</param> /// <param name="maxDepth">The max depth of the object to include.</param> /// <param name="excludedPropertyNames">Any property names that should be excluded</param> /// <param name="ignoreSerializationErrors">Specifies wether properties that throw errors while serializing be ignored</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Current. /// </param> public static void AddObject(this Error error, object data, string name = null, int?maxDepth = null, ICollection <string> excludedPropertyNames = null, bool ignoreSerializationErrors = false, ExceptionlessClient client = null) { if (client == null) { client = ExceptionlessClient.Current; } if (data == null) { return; } ExtendedDataInfo info; if (data is ExtendedDataInfo) { info = data as ExtendedDataInfo; } else { info = new ExtendedDataInfo { Data = data, Name = name, MaxDepthToSerialize = maxDepth, ExcludedPropertyNames = excludedPropertyNames != null?client.Configuration.DataExclusions.Union(excludedPropertyNames).ToArray() : client.Configuration.DataExclusions, IgnoreSerializationErrors = ignoreSerializationErrors }; } AddObject(error, info); }
/// <summary> /// Adds the object to extended data. /// </summary> /// <param name="data">The error.</param> /// <param name="value">The data object to add.</param> /// <param name="name">The name of the object to add.</param> /// <param name="maxDepth">The max depth of the object to include.</param> /// <param name="excludedPropertyNames">Any property names that should be excluded</param> /// <param name="ignoreSerializationErrors">Specifies wether properties that throw errors while serializing be ignored</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Default. /// </param> public static void AddObject(this IData data, object value, string name = null, int?maxDepth = null, IEnumerable <string> excludedPropertyNames = null, bool ignoreSerializationErrors = false, ExceptionlessClient client = null) { if (client == null) { client = ExceptionlessClient.Default; } if (value == null) { return; } ExtendedDataInfo info; if (value is ExtendedDataInfo) { info = value as ExtendedDataInfo; } else { info = new ExtendedDataInfo { Data = value, Name = name, MaxDepthToSerialize = maxDepth, ExcludedPropertyNames = excludedPropertyNames != null?client.Configuration.DataExclusions.Union(excludedPropertyNames).ToArray() : client.Configuration.DataExclusions.ToArray(), IgnoreSerializationErrors = ignoreSerializationErrors }; } AddObject(data, info); }
/// <summary> /// Adds the object to extended data. /// </summary> /// <param name="data">The error.</param> /// <param name="value">The data object to add.</param> /// <param name="name">The name of the object to add. If not specified, the name will be implied from the object type.</param> /// <param name="maxDepth">The max depth of the object to include.</param> /// <param name="excludedPropertyNames">Any property names that should be excluded</param> /// <param name="ignoreSerializationErrors">Specifies wether properties that throw errors while serializing be ignored</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Default. /// </param> public static void AddObject(this IData data, object value, string name = null, int?maxDepth = null, IEnumerable <string> excludedPropertyNames = null, bool ignoreSerializationErrors = false, ExceptionlessClient client = null) { if (client == null) { client = ExceptionlessClient.Default; } if (value == null) { return; } ExtendedDataInfo info; if (value is ExtendedDataInfo) { info = value as ExtendedDataInfo; } else { info = new ExtendedDataInfo { Data = value, Name = name, MaxDepthToSerialize = maxDepth, IgnoreSerializationErrors = ignoreSerializationErrors }; if (excludedPropertyNames != null) { info.ExcludedPropertyNames.AddRange(excludedPropertyNames); } } AddObject(data, info, client); }
/// <summary> /// Adds the object to extended data. /// </summary> /// <param name="data">The error to add the object to.</param> /// <param name="info">The data object to add.</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Default. /// </param> public static void AddObject(this IData data, ExtendedDataInfo info, ExceptionlessClient client = null) { if (client == null) { client = ExceptionlessClient.Default; } if (info == null || info.Data == null) { return; } string name = info.Data.GetType().Name; if (!String.IsNullOrEmpty(info.Name)) { name = info.Name; } string json = String.Empty; string[] excludedPropertyNames = info.ExcludedPropertyNames != null?client.Configuration.DataExclusions.Union(info.ExcludedPropertyNames).ToArray() : client.Configuration.DataExclusions.ToArray(); try { var serializer = DependencyResolver.Default.GetJsonSerializer(); json = serializer.Serialize(info.Data, excludedPropertyNames, info.MaxDepthToSerialize.HasValue ? info.MaxDepthToSerialize.Value : 5, info.IgnoreSerializationErrors); } catch (Exception ex) { json = ex.ToString(); } if (data.Data.ContainsKey(name)) { data.Data[name] = json; } else { data.Data.Add(name, json); } }
/// <summary> /// Adds the object to extended data. /// </summary> /// <param name="error">The error to add the object to.</param> /// <param name="info">The data object to add.</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Current. /// </param> public static void AddObject(this Error error, ExtendedDataInfo info, ExceptionlessClient client = null) { if (client == null) { client = ExceptionlessClient.Current; } if (info == null || info.Data == null) { return; } string name = info.Data.GetType().Name; if (!String.IsNullOrEmpty(info.Name)) { name = info.Name; } string json = String.Empty; ICollection <string> excludedPropertyNames = info.ExcludedPropertyNames != null?client.Configuration.DataExclusions.Union(info.ExcludedPropertyNames).ToArray() : client.Configuration.DataExclusions; try { json = ModelSerializer.Current.SerializeToString(info.Data, info.MaxDepthToSerialize, excludedPropertyNames, info.IgnoreSerializationErrors); } catch (Exception ex) { json = ex.ToString(); } if (error.ExtendedData.ContainsKey(name)) { error.ExtendedData[name] = json; } else { error.ExtendedData.Add(name, json); } }
/// <summary> /// Adds the object to extended data. /// </summary> /// <param name="data">The error to add the object to.</param> /// <param name="info">The data object to add.</param> /// <param name="client"> /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use /// ExceptionlessClient.Default. /// </param> public static void AddObject(this IData data, ExtendedDataInfo info, ExceptionlessClient client = null) { if (client == null) { client = ExceptionlessClient.Default; } if (info == null || info.Data == null) { return; } string[] exclusions = info.ExcludedPropertyNames != null ? client.Configuration.DataExclusions.Union(info.ExcludedPropertyNames).ToArray() : client.Configuration.DataExclusions.ToArray(); string name = !String.IsNullOrWhiteSpace(info.Name) ? info.Name.Trim() : null; Type dataType = info.Data.GetType(); if (String.IsNullOrEmpty(name)) { name = dataType.Name; int index = 1; while (data.Data.ContainsKey(name)) { name = dataType.Name + index++; } } else if (name.AnyWildcardMatches(exclusions, true)) { return; } if (dataType == typeof(bool) || dataType == typeof(string) || dataType.IsNumeric()) { if (data.Data.ContainsKey(name)) { data.Data[name] = info.Data; } else { data.Data.Add(name, info.Data); } return; } string json; try { if (dataType.IsPrimitiveType()) { json = info.Data.ToString(); } else { var serializer = client.Configuration.Resolver.GetJsonSerializer(); json = serializer.Serialize(info.Data, exclusions, info.MaxDepthToSerialize.HasValue ? info.MaxDepthToSerialize.Value : 5, info.IgnoreSerializationErrors); } } catch (Exception ex) { json = ex.ToString(); } if (String.IsNullOrEmpty(json)) { return; } if (data.Data.ContainsKey(name)) { data.Data[name] = json; } else { data.Data.Add(name, json); } }