Beispiel #1
0
        /// <summary>
        /// Appends information about an exception to string builder.
        /// </summary>
        /// <param name="sb">The string builder.</param>
        /// <param name="rootException">The root exception.</param>
        private void AppendException(StringBuilder sb, Exception rootException)
        {
            Exception e       = rootException;
            int       nesting = 0;

            while (e != null)
            {
#if !SILVERLIGHT
                Win32Exception winErr = e as Win32Exception;

                if (nesting > 0)
                {
                    sb.AppendFormat("\r\n------ Nested:{0} ------\r\n", nesting);
                }

                if (winErr == null)
                {
                    sb.AppendFormat((IFormatProvider)null, "{0}: {1} [\"{2}\"]\r\n", Type.ToString(), e.GetType().Name, e.Message.Replace("\r\n", " "));
                }
                else
                {
                    sb.AppendFormat((IFormatProvider)null, "{0}: {1} [\"{2}\"] [WINERR={3}]\r\n", Type.ToString(), e.GetType().Name, e.Message.Replace("\r\n", " "), winErr.NativeErrorCode);
                }
#else
                sb.AppendFormat((IFormatProvider)null, "{0}: {1} [\"{2}\"]\r\n", Type.ToString(), e.GetType().Name, e.Message.Replace("\r\n", " "));
#endif

                ICustomExceptionLogger custom;

                custom = e as ICustomExceptionLogger;
                if (custom != null)
                {
                    custom.Log(sb);
                }

                sb.Append("\r\n");
                sb.Append(e.StackTrace);
                sb.Append("\r\n");

                e = e.InnerException;
                nesting++;
            }

            // Handler serialization of any aggregated exceptions.

            var aggregation = rootException as AggregateException;

            if (aggregation != null)
            {
                sb.Append("\r\n");
                sb.Append(" ============= Aggregated Exceptions =============\r\n");

                foreach (var subException in aggregation.InnerExceptions)
                {
                    AppendException(sb, subException);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Computes an MD5 hash code for the log entry
        /// </summary>
        /// <param name="extension">The extended entry information (or <c>null</c>).</param>
        /// <param name="entryType">The log entry type.</param>
        /// <param name="message">The log message (or <c>null</c>).</param>
        /// <param name="e">The logged exception (or <c>null</c>).</param>
        /// <returns>The computed hash.</returns>
        private static MD5Key ComputeMD5Hash(ISysLogEntryExtension extension, SysLogEntryType entryType, string message, Exception e)
        {
            StringBuilder sb = new StringBuilder(1024);

            if (extension != null)
            {
                sb.Append(extension.Format());
            }

            sb.Append('\t');

            sb.Append(entryType.ToString());
            sb.Append('\t');

            if (message != null)
            {
                sb.Append(message);
            }

            sb.Append('\t');

            if (e != null)
            {
                sb.Append(e.GetType().FullName);
                sb.Append('\t');
                sb.Append(e.Message);
                sb.Append('\t');
                sb.Append(e.StackTrace.ToString());
            }

            return(new MD5Key(MD5Hasher.Compute(sb.ToString())));
        }