BSky.Statistics.Common.Log.ExceptionToString C# (CSharp) Method

ExceptionToString() private static method

private static ExceptionToString ( Exception exception ) : string
exception System.Exception
return string
        private static string ExceptionToString(Exception exception)
        {
            string exceptionString = "";

            if (exception != null)
            {
                Exception e = exception;
                do
                {
                    exceptionString += e.Message;

                    // Add additional info for COMExceptions
                    if (e is System.Runtime.InteropServices.COMException)
                    {
                        System.Runtime.InteropServices.COMException cex = (System.Runtime.InteropServices.COMException)exception;
                        exceptionString += " (HRESULT : 0x" + cex.ErrorCode.ToString("X") + ")";
                    }

                    e = e.InnerException;
                    if (e != null)
                    {
                        exceptionString += " | ";
                    }
                } while (e != null);


                exceptionString += " | ";

                if (exception.StackTrace != null)
                {
                    exceptionString += "Trace: " + NewLine + exception.StackTrace.ToString() + NewLine;
                }
                else
                {
                    exceptionString += "Trace: Not Available" + NewLine;
                }
            }

            return exceptionString;
        }