Esempio n. 1
0
 private static void WriteExceptionToTraceString(XmlTextWriter xml, Exception exception, int remainingLength, int remainingAllowedRecursionDepth)
 {
     if (remainingAllowedRecursionDepth >= 1)
     {
         if (EtwDiagnosticTrace.WriteStartElement(xml, "Exception", ref remainingLength))
         {
             try
             {
                 List <Tuple <string, string> > tuples = new List <Tuple <string, string> >();
                 tuples.Add(new Tuple <string, string>("ExceptionType", DiagnosticTraceBase.XmlEncode(exception.GetType().AssemblyQualifiedName)));
                 tuples.Add(new Tuple <string, string>("Message", DiagnosticTraceBase.XmlEncode(exception.Message)));
                 tuples.Add(new Tuple <string, string>("StackTrace", DiagnosticTraceBase.XmlEncode(DiagnosticTraceBase.StackTraceString(exception))));
                 tuples.Add(new Tuple <string, string>("ExceptionString", DiagnosticTraceBase.XmlEncode(exception.ToString())));
                 IList <Tuple <string, string> > tuples1 = tuples;
                 Win32Exception win32Exception           = exception as Win32Exception;
                 if (win32Exception != null)
                 {
                     int nativeErrorCode = win32Exception.NativeErrorCode;
                     tuples1.Add(new Tuple <string, string>("NativeErrorCode", nativeErrorCode.ToString("X", CultureInfo.InvariantCulture)));
                 }
                 foreach (Tuple <string, string> tuple in tuples1)
                 {
                     if (EtwDiagnosticTrace.WriteXmlElementString(xml, tuple.Item1, tuple.Item2, ref remainingLength))
                     {
                         continue;
                     }
                     return;
                 }
                 if (exception.Data != null && exception.Data.Count > 0)
                 {
                     string exceptionData = EtwDiagnosticTrace.GetExceptionData(exception);
                     if (exceptionData.Length < remainingLength)
                     {
                         xml.WriteRaw(exceptionData);
                         remainingLength = remainingLength - exceptionData.Length;
                     }
                 }
                 if (exception.InnerException != null)
                 {
                     string innerException = EtwDiagnosticTrace.GetInnerException(exception, remainingLength, remainingAllowedRecursionDepth - 1);
                     if (!string.IsNullOrEmpty(innerException) && innerException.Length < remainingLength)
                     {
                         xml.WriteRaw(innerException);
                     }
                 }
             }
             finally
             {
                 xml.WriteEndElement();
             }
             return;
         }
         else
         {
             return;
         }
     }
     else
     {
         return;
     }
 }