/// <summary> /// Creates an exception data object. /// </summary> /// <param name="type">The exception type full name.</param> /// <param name="message">The exception message text.</param> /// <param name="stackTrace">The exception stack trace.</param> /// <param name="properties">The exception properties, or <see cref="NoProperties"/> /// if none.</param> /// <param name="innerException">The inner exception data, or null if none.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="type"/>, /// <paramref name="message"/>, <paramref name="properties"/> /// or <paramref name="stackTrace"/> is null.</exception> public ExceptionData(string type, string message, StackTraceData stackTrace, PropertySet properties, ExceptionData innerException) { if (type == null) { throw new ArgumentNullException("type"); } if (message == null) { throw new ArgumentNullException("message"); } if (stackTrace == null) { throw new ArgumentNullException("stackTrace"); } if (properties == null) { throw new ArgumentNullException("properties"); } this.type = type; this.message = message; this.stackTrace = stackTrace; this.properties = properties.Count == 0 ? NoProperties : properties.AsReadOnly(); this.innerException = innerException; }
/// <summary> /// Creates an exception data object from an exception. /// </summary> /// <remarks> /// <para> /// Captures the exception type, message, stack trace and properties from /// the exception object. To filter out specific properties, mark them with /// <see cref="SystemInternalAttribute"/>. /// </para> /// </remarks> /// <param name="exception">The exception.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="exception"/> is null.</exception> public ExceptionData(Exception exception) { if (exception == null) { throw new ArgumentNullException("exception"); } type = exception.GetType().FullName; message = ExceptionUtils.SafeGetMessage(exception); stackTrace = new StackTraceData(ExceptionUtils.SafeGetStackTrace(exception)); properties = ExtractExceptionProperties(exception).AsReadOnly(); if (exception.InnerException != null) { innerException = new ExceptionData(exception.InnerException); } }
/// <inheritdoc /> public ExceptionData Normalize() { string normalizedType = NormalizationUtils.NormalizeName(type); string normalizedMessage = NormalizationUtils.NormalizeXmlText(message); StackTraceData normalizedStackTrace = stackTrace.Normalize(); PropertySet normalizedProperties = NormalizationUtils.NormalizeCollection <PropertySet, KeyValuePair <string, string> >(properties, () => new PropertySet(), x => new KeyValuePair <string, string>(NormalizationUtils.NormalizeName(x.Key), NormalizationUtils.NormalizeXmlText(x.Value)), (x, y) => x.Key == y.Key && x.Value == y.Value); ExceptionData normalizedInnerException = innerException != null?innerException.Normalize() : null; if (ReferenceEquals(type, normalizedType) && ReferenceEquals(message, normalizedMessage) && ReferenceEquals(stackTrace, normalizedStackTrace) && ReferenceEquals(properties, normalizedProperties) && ReferenceEquals(innerException, normalizedInnerException)) { return(this); } return(new ExceptionData(normalizedType, normalizedMessage, normalizedStackTrace, normalizedProperties, normalizedInnerException)); }