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;
}