Opc.Ua.ServiceResult.BuildExceptionTrace C# (CSharp) Method

BuildExceptionTrace() public static method

Returns a string containing all nested exceptions.
public static BuildExceptionTrace ( Exception exception ) : string
exception System.Exception
return string
		public static string BuildExceptionTrace(Exception exception)
		{
			StringBuilder buffer = new StringBuilder();

			while (exception != null)
			{
				if (buffer.Length > 0)
				{
					buffer.AppendFormat(CultureInfo.InvariantCulture, "\r\n\r\n");
				}

                buffer.AppendFormat(CultureInfo.InvariantCulture, ">>> {0}", exception.Message);

                if (!String.IsNullOrEmpty(exception.StackTrace))
                {
				    string[] trace = exception.StackTrace.Split(new char[] {'\r','\n'});

				    for (int ii = 0; ii < trace.Length; ii++)
				    {
					    if (trace[ii] != null && trace[ii].Length > 0)
					    {
                            buffer.AppendFormat(CultureInfo.InvariantCulture, "\r\n--- {0}", trace[ii]);
					    }
				    }
                }

				exception = exception.InnerException;
			}

			return buffer.ToString();
		}
		#endregion