コード例 #1
0
ファイル: InteropApi.cs プロジェクト: zmyer/service-fabric
        private static string CreateThreadErrorMessage(Exception ex, bool includeStackTrace = true)
        {
            const int MaxCharactersOfMessageToCopy = 512;

            // there are limits such as 4k for the health report size and 4k for the interop
            // use a smaller limit here
            const int MaxLength = 4000;

            ExceptionStringBuilder sb = new ExceptionStringBuilder(MaxLength);

            var exception = ex;

            while (exception != null)
            {
                if (exception.Message != null)
                {
                    sb.Append(GetExceptionInfoString(exception.GetType(), exception.HResult), MaxCharactersOfMessageToCopy);
                    sb.AppendLine();
                    sb.Append(exception.Message, MaxCharactersOfMessageToCopy);
                    sb.AppendLine();
                }
                exception = exception.InnerException;
            }

            if (includeStackTrace)
            {
                string st = GetErrorStackTrace(ex);
                sb.Append(st);
            }

            return(sb.ToString());
        }
コード例 #2
0
        private static string CreateThreadErrorMessage(Exception ex, bool includeStackTrace = true)
        {
            const int MaxCharactersOfMessageToCopy = 512;

            // there are limits such as 4k for the health report size and 4k for the interop
            // use a smaller limit here
            const int MaxLength = 4000;

            ExceptionStringBuilder sb = new ExceptionStringBuilder(MaxLength);

            int    HResult = ex.HResult;
            string message = ex.Message;

            System.Type type = ex.GetType();

            sb.Append(GetExceptionInfoString(type, HResult));
            sb.AppendLine();

            FabricException fabricEx = ex as FabricException;

            if (fabricEx != null && (fabricEx.InnerException != null))
            {
                // Add only 256 bytes of the message to prevent it from overflowing the health report
                sb.Append(message, MaxCharactersOfMessageToCopy / 2);
                sb.AppendLine();

                Exception inner = fabricEx.InnerException;

                sb.Append(GetExceptionInfoString(inner.GetType(), inner.HResult));
                sb.AppendLine();

                // Outer exception + Inner exception message should be upto 512 bytes to prevent it from overflowing the health report
                sb.Append(inner.Message, MaxCharactersOfMessageToCopy);
            }
            else
            {
                // Add only 512 bytes of the message to prevent it from overflowing the health report
                sb.Append(message, MaxCharactersOfMessageToCopy);
            }

            if (includeStackTrace)
            {
                // Add the stack trace
                sb.AppendLine();
                sb.Append(ex.StackTrace);
            }

            return(sb.ToString());
        }