/// <summary> /// Builds a readable representation of the stack trace, specifying /// the format for backwards compatibility. /// </summary> internal string ToString(TraceFormat traceFormat) { var sb = new StringBuilder(256); ToString(traceFormat, sb); return(sb.ToString()); }
public static void AddParameters(ref string s, IDictionary parameters, TraceFormat tf) { if (parameters == null) { return; } bool isHtml = (tf == TraceFormat.Html); foreach (string key in parameters.Keys) { var pv = parameters[key]; string v = pv == null ? "null" : pv is DateTime ? string.Format("{0:yyyy-MM-dd HH:mm:ss.fff}", pv) : string.Format("{0}", pv); if (isHtml) { v = System.Net.WebUtility.HtmlEncode(v); v = "<span class=\"Pre\">" + v + "</span>"; AddRow(ref s, key, v); } else { s += string.Format("{0}: {1}\r\n", key, v); } } }
[Test] public void LoggingOnFailure() { status s = x[false]?[done(log && "Testing")]; // Question mark indicates we don't know the subtask managed by this // decorator just yet o(TraceFormat.LogTrace(s.trace), "<D> Bear ?"); }
[Test] public void LoggingOnSuccess() { status s = x[true]?[done(log && "Testing")]; // Question mark drops because we just don't format the target object // on success (since it gets evaluated, it has its own format phase) o(TraceFormat.LogTrace(s.trace), "<D> Bug -> TestConditional.LoggingOnSuccess (Testing)"); }
internal string ToString(TraceFormat traceFormat) { var stackTraceString = _builder.ToString(); if (traceFormat == TraceFormat.Normal && stackTraceString.EndsWith(Environment.NewLine)) { return(stackTraceString.Substring(0, stackTraceString.Length - Environment.NewLine.Length)); } return(stackTraceString); }
internal string ToString(TraceFormat traceFormat) { if (_stackFrames == null) { return(""); } StringBuilder builder = new StringBuilder(); foreach (StackFrame frame in _stackFrames) { frame.AppendToStackTrace(builder); } return(builder.ToString()); }
internal void ToString(TraceFormat traceFormat, StringBuilder builder) { if (_stackFrames == null) { return; } foreach (StackFrame frame in _stackFrames) { frame.AppendToStackTrace(builder); } if (traceFormat == TraceFormat.Normal && builder.Length >= Environment.NewLine.Length) { builder.Length -= Environment.NewLine.Length; } }
internal string ToString(TraceFormat traceFormat) { if (_stackFrames == null) { return(""); } StringBuilder builder = new StringBuilder(); foreach (StackFrame frame in _stackFrames) { frame.AppendToStackTrace(builder); } if (traceFormat == TraceFormat.TrailingNewLine) { builder.Append(Environment.NewLine); } return(builder.ToString()); }
public void setTraceFormat(TraceFormat traceFormat) { this.traceFormat = traceFormat; }
public static string TraceToString(StackTrace st, TraceFormat tf, int startFrameIndex = 0) { bool isHtml = (tf == TraceFormat.Html); string newLine = (isHtml) ? "<br />" + Environment.NewLine : Environment.NewLine; bool flag = true; bool flag2 = true; var builder = new StringBuilder(0xff); if (isHtml) { builder.Append("<span class=\"Mono\">"); } for (int i = startFrameIndex; i < st.FrameCount; i++) { StackFrame frame = st.GetFrame(i); MethodBase method = frame.GetMethod(); if (method != null) { if (flag2) { flag2 = false; } else { builder.Append(newLine); } if (isHtml) { builder.Append(" <span style=\"color: #808080;\">at</span> "); } else { builder.Append(" at "); } Type declaringType = method.DeclaringType; bool isForm = IsFormStackFrame(frame); if (declaringType != null) { string ns = declaringType.Namespace.Replace('+', '.'); string name = declaringType.Name.Replace('+', '.'); if (isHtml) { if (isForm) { builder.Append("<span style=\"font-weight: bold;\">"); } builder.Append(System.Net.WebUtility.HtmlEncode(ns)); builder.Append("."); builder.AppendFormat("<span style=\"color: #2B91AF; \">{0}</span>", System.Net.WebUtility.HtmlEncode(name)); if (isForm) { builder.Append("</span>"); } } else { builder.AppendFormat("{0}.{1}", ns, name); } builder.Append("."); } if (isHtml && isForm) { builder.Append("<span style=\"font-weight: bold; color: #800000;\">"); } builder.Append(method.Name); if ((method is MethodInfo) && ((MethodInfo)method).IsGenericMethod) { Type[] genericArguments = ((MethodInfo)method).GetGenericArguments(); builder.Append("["); int index = 0; bool flag3 = true; while (index < genericArguments.Length) { if (!flag3) { builder.Append(","); } else { flag3 = false; } builder.Append(genericArguments[index].Name); index++; } builder.Append("]"); } builder.Append("("); ParameterInfo[] parameters = method.GetParameters(); bool flag4 = true; for (int j = 0; j < parameters.Length; j++) { var param = parameters[j]; if (!flag4) { builder.Append(", "); } else { flag4 = false; } string paramType = "<UnknownType>"; bool isClass = false; if (param.ParameterType != null) { isClass = param.ParameterType.IsClass; paramType = param.ParameterType.Name; } if (isHtml) { if (isClass) { builder.Append("<span style=\"color: #2B91AF; \">"); } builder.Append(System.Net.WebUtility.HtmlEncode(paramType)); if (isClass) { builder.Append("</span>"); } builder.Append(" "); builder.Append(System.Net.WebUtility.HtmlEncode(paramType)); } else { builder.AppendFormat("{0} {1}", paramType, param.Name); } } builder.Append(")"); if (isHtml && isForm) { builder.Append("</span>"); } if (flag && (frame.GetILOffset() != -1)) { string fileName = null; try { fileName = frame.GetFileName(); } catch (NotSupportedException) { flag = false; } catch (SecurityException) { flag = false; } if (fileName != null) { var lineNumber = frame.GetFileLineNumber(); var columnNumber = frame.GetFileColumnNumber(); string format; if (isHtml) { builder.Append("<br /> "); var fnHtml = System.Net.WebUtility.HtmlEncode(fileName); var fnColor = isForm ? "#800000" : "#000000"; var fnSpan = string.Format("<span style=\"color: {0};\">{1}</span>", fnColor, fnHtml); // Add file as link. var addLink = false; if (addLink) { var fnLink = System.Net.WebUtility.UrlEncode(fileName.Replace("\\", "/")).Replace("+", "%20"); builder.AppendFormat("<a href=\"file:///{0}\" style=\"text-decoration: none; color: #000000;\">{1}</a>", fnLink, fnSpan); } else { builder.AppendFormat(fnSpan); } builder.AppendFormat("<span style=\"color: #808080;\">,</span> {0}", lineNumber); builder.AppendFormat("<span style=\"color: #808080;\">:{0}</span>", columnNumber); } else { format = " in {0}, {1}:{2}"; builder.AppendFormat(format, fileName, lineNumber, columnNumber); } } } } } if (isHtml || tf == TraceFormat.TrailingNewLine) { builder.Append(newLine); } if (isHtml) { builder.Append("</span>"); } return(builder.ToString()); }
string ExceptionToString(Exception ex, bool needFileLineInfo, TraceFormat tf) { bool isHtml = (tf == TraceFormat.Html); string newLine = isHtml ? "<br />" + Environment.NewLine : Environment.NewLine; var builder = new StringBuilder(0xff); if (isHtml) { builder.Append("<span class=\"Mono\">"); } builder.Append(getText(isHtml, GetClassName(ex))); if (!string.IsNullOrEmpty(ex.Message)) { builder.Append(": "); builder.Append(getText(isHtml, ex.Message)); } //builder.Append(newLine); var stackTrace = new StackTrace(ex, needFileLineInfo); StackTrace fullTrace = null; int startFrameIndex = 0; // If use unstable version. // Can loose information about original line of exception. if (ErrorUseNewStackTrace) { // Get full stack trace from root to the current line. fullTrace = new StackTrace(needFileLineInfo); // Get current class. var currentClass = fullTrace.GetFrame(0).GetMethod().DeclaringType; // Get deepest/top method from stack trace. var method = stackTrace.FrameCount > 0 ? stackTrace.GetFrame(0).GetMethod() : null; // Loop through full stack trace. for (int i = 0; i < fullTrace.FrameCount; i++) { // Get frame method. var m = fullTrace.GetFrame(i).GetMethod(); if (m == null) { continue; } // If same method was found then... if (m.Equals(method)) { // Start displaying stack trace from this method // when converting stack trace to string. startFrameIndex = i; break; } // If method of full frame is located inside this class then... if (m.DeclaringType.Equals(currentClass)) { // Skip this frame. startFrameIndex = i + 1; } } } // Use full trace is exists. var trace = fullTrace ?? stackTrace; if (trace.FrameCount > 0) { builder.Append(newLine); builder.Append(TraceToString(trace, tf, startFrameIndex)); } //if (ex.InnerException != null) //{ // builder.Append(getText(isHtml, " ---> ")); // builder.Append(ExceptionToString(ex.InnerException, needFileLineInfo, tf)); // builder.Append(newLine); //} if (isHtml) { builder.Append("</span>"); } return(builder.ToString()); }
internal string ToString(TraceFormat traceFormat) { string resourceString = "at"; string format = "in {0}:line {1}"; if (traceFormat != TraceFormat.NoResourceLookup) { resourceString = Environment.GetResourceString("Word_At"); format = Environment.GetResourceString("StackTrace_InFileLineNumber"); } bool flag = true; StringBuilder builder = new StringBuilder(0xff); for (int i = 0; i < this.m_iNumOfFrames; i++) { StackFrame frame = this.GetFrame(i); MethodBase method = frame.GetMethod(); if (method != null) { if (flag) { flag = false; } else { builder.Append(Environment.NewLine); } builder.AppendFormat(CultureInfo.InvariantCulture, " {0} ", new object[] { resourceString }); Type declaringType = method.DeclaringType; if (declaringType != null) { builder.Append(declaringType.FullName.Replace('+', '.')); builder.Append("."); } builder.Append(method.Name); if ((method is MethodInfo) && ((MethodInfo)method).IsGenericMethod) { Type[] genericArguments = ((MethodInfo)method).GetGenericArguments(); builder.Append("["); int index = 0; bool flag2 = true; while (index < genericArguments.Length) { if (!flag2) { builder.Append(","); } else { flag2 = false; } builder.Append(genericArguments[index].Name); index++; } builder.Append("]"); } builder.Append("("); ParameterInfo[] parameters = method.GetParameters(); bool flag3 = true; for (int j = 0; j < parameters.Length; j++) { if (!flag3) { builder.Append(", "); } else { flag3 = false; } string name = "<UnknownType>"; if (parameters[j].ParameterType != null) { name = parameters[j].ParameterType.Name; } builder.Append(name + " " + parameters[j].Name); } builder.Append(")"); if (frame.GetILOffset() != -1) { string fileName = null; try { fileName = frame.GetFileName(); } catch (SecurityException) { } if (fileName != null) { builder.Append(' '); builder.AppendFormat(CultureInfo.InvariantCulture, format, new object[] { fileName, frame.GetFileLineNumber() }); } } } } if (traceFormat == TraceFormat.TrailingNewLine) { builder.Append(Environment.NewLine); } return(builder.ToString()); }
[System.Security.SecurityCritical] // auto-generated #endif internal String ToString(TraceFormat traceFormat) { bool displayFilenames = true; // we'll try, but demand may fail String word_At = "at"; String inFileLineNum = "in {0}:line {1}"; if (traceFormat != TraceFormat.NoResourceLookup) { word_At = Environment.GetResourceString("Word_At"); inFileLineNum = Environment.GetResourceString("StackTrace_InFileLineNumber"); } bool fFirstFrame = true; StringBuilder sb = new StringBuilder(255); for (int iFrameIndex = 0; iFrameIndex < m_iNumOfFrames; iFrameIndex++) { StackFrame sf = GetFrame(iFrameIndex); MethodBase mb = sf.GetMethod(); if (mb != null) { // We want a newline at the end of every line except for the last if (fFirstFrame) { fFirstFrame = false; } else { sb.Append(Environment.NewLine); } sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At); Type t = mb.DeclaringType; // if there is a type (non global method) print it if (t != null) { // Append t.FullName, replacing '+' with '.' string fullName = t.FullName; for (int i = 0; i < fullName.Length; i++) { char ch = fullName[i]; sb.Append(ch == '+' ? '.' : ch); } sb.Append('.'); } sb.Append(mb.Name); // deal with the generic portion of the method if (mb is MethodInfo && ((MethodInfo)mb).IsGenericMethod) { Type[] typars = ((MethodInfo)mb).GetGenericArguments(); sb.Append('['); int k = 0; bool fFirstTyParam = true; while (k < typars.Length) { if (fFirstTyParam == false) { sb.Append(','); } else { fFirstTyParam = false; } sb.Append(typars[k].Name); k++; } sb.Append(']'); } ParameterInfo[] pi = null; #if FEATURE_CORECLR try { #endif pi = mb.GetParameters(); #if FEATURE_CORECLR } catch { // The parameter info cannot be loaded, so we don't // append the parameter list. } #endif if (pi != null) { // arguments printing sb.Append('('); bool fFirstParam = true; for (int j = 0; j < pi.Length; j++) { if (fFirstParam == false) { sb.Append(", "); } else { fFirstParam = false; } String typeName = "<UnknownType>"; if (pi[j].ParameterType != null) { typeName = pi[j].ParameterType.Name; } sb.Append(typeName); sb.Append(' '); sb.Append(pi[j].Name); } sb.Append(')'); } // source location printing if (displayFilenames && (sf.GetILOffset() != -1)) { // If we don't have a PDB or PDB-reading is disabled for the module, // then the file name will be null. String fileName = null; // Getting the filename from a StackFrame is a privileged operation - we won't want // to disclose full path names to arbitrarily untrusted code. Rather than just omit // this we could probably trim to just the filename so it's still mostly usefull. try { fileName = sf.GetFileName(); } catch (SecurityException) { // If the demand for displaying filenames fails, then it won't // succeed later in the loop. Avoid repeated exceptions by not trying again. displayFilenames = false; } if (fileName != null) { // tack on " in c:\tmp\MyFile.cs:line 5" sb.Append(' '); sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber()); } } #if FEATURE_EXCEPTIONDISPATCHINFO if (sf.GetIsLastFrameFromForeignExceptionStackTrace()) { sb.Append(Environment.NewLine); sb.Append(Environment.GetResourceString("Exception_EndStackTraceFromPreviousThrow")); } #endif // FEATURE_EXCEPTIONDISPATCHINFO } } if (traceFormat == TraceFormat.TrailingNewLine) { sb.Append(Environment.NewLine); } return(sb.ToString()); }
[System.Security.SecurityCritical] // auto-generated #endif internal String ToString(TraceFormat traceFormat) { bool displayFilenames = true; // we'll try, but demand may fail String word_At = "at"; String inFileLineNum = "in {0}:line {1}"; if(traceFormat != TraceFormat.NoResourceLookup) { word_At = Environment.GetResourceString("Word_At"); inFileLineNum = Environment.GetResourceString("StackTrace_InFileLineNumber"); } bool fFirstFrame = true; StringBuilder sb = new StringBuilder(255); for (int iFrameIndex = 0; iFrameIndex < m_iNumOfFrames; iFrameIndex++) { StackFrame sf = GetFrame(iFrameIndex); MethodBase mb = sf.GetMethod(); if (mb != null) { // We want a newline at the end of every line except for the last if (fFirstFrame) fFirstFrame = false; else sb.Append(Environment.NewLine); sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At); Type t = mb.DeclaringType; // if there is a type (non global method) print it if (t != null) { // Append t.FullName, replacing '+' with '.' string fullName = t.FullName; for (int i = 0; i < fullName.Length; i++) { char ch = fullName[i]; sb.Append(ch == '+' ? '.' : ch); } sb.Append('.'); } sb.Append(mb.Name); // deal with the generic portion of the method if (mb is MethodInfo && ((MethodInfo)mb).IsGenericMethod) { Type[] typars = ((MethodInfo)mb).GetGenericArguments(); sb.Append('['); int k=0; bool fFirstTyParam = true; while (k < typars.Length) { if (fFirstTyParam == false) sb.Append(','); else fFirstTyParam = false; sb.Append(typars[k].Name); k++; } sb.Append(']'); } ParameterInfo[] pi = null; #if FEATURE_CORECLR try { #endif pi = mb.GetParameters(); #if FEATURE_CORECLR } catch { // The parameter info cannot be loaded, so we don't // append the parameter list. } #endif if (pi != null) { // arguments printing sb.Append('('); bool fFirstParam = true; for (int j = 0; j < pi.Length; j++) { if (fFirstParam == false) sb.Append(", "); else fFirstParam = false; String typeName = "<UnknownType>"; if (pi[j].ParameterType != null) typeName = pi[j].ParameterType.Name; sb.Append(typeName); sb.Append(' '); sb.Append(pi[j].Name); } sb.Append(')'); } // source location printing if (displayFilenames && (sf.GetILOffset() != -1)) { // If we don't have a PDB or PDB-reading is disabled for the module, // then the file name will be null. String fileName = null; // Getting the filename from a StackFrame is a privileged operation - we won't want // to disclose full path names to arbitrarily untrusted code. Rather than just omit // this we could probably trim to just the filename so it's still mostly usefull. try { fileName = sf.GetFileName(); } #if FEATURE_CAS_POLICY catch (NotSupportedException) { // Having a deprecated stack modifier on the callstack (such as Deny) will cause // a NotSupportedException to be thrown. Since we don't know if the app can // access the file names, we'll conservatively hide them. displayFilenames = false; } #endif // FEATURE_CAS_POLICY catch (SecurityException) { // If the demand for displaying filenames fails, then it won't // succeed later in the loop. Avoid repeated exceptions by not trying again. displayFilenames = false; } if (fileName != null) { // tack on " in c:\tmp\MyFile.cs:line 5" sb.Append(' '); sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber()); } } #if FEATURE_EXCEPTIONDISPATCHINFO if (sf.GetIsLastFrameFromForeignExceptionStackTrace()) { sb.Append(Environment.NewLine); sb.Append(Environment.GetResourceString("Exception_EndStackTraceFromPreviousThrow")); } #endif // FEATURE_EXCEPTIONDISPATCHINFO } } if(traceFormat == TraceFormat.TrailingNewLine) sb.Append(Environment.NewLine); return sb.ToString(); }
// Builds a readable representation of the stack trace, specifying // the format for backwards compatibility. internal String ToString( TraceFormat traceFormat ) { String word_At = "at"; String inFileLineNum = "in {0}:line {1}"; if( traceFormat != TraceFormat.NoResourceLookup ) { word_At = Environment.GetResourceString("Word_At"); inFileLineNum = Environment.GetResourceString("StackTrace_InFileLineNumber"); } bool fFirstFrame = true; StringBuilder sb = new StringBuilder(255); for (int iFrameIndex=0; iFrameIndex < m_iNumOfFrames; iFrameIndex++) { StackFrame sf = GetFrame(iFrameIndex); MethodBase mb = sf.GetMethod(); if (mb != null) { // We want a newline at the end of every line except for the last if (fFirstFrame) fFirstFrame = false; else sb.Append( Environment.NewLine ); sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At); Type t = mb.DeclaringType; // if there is a type (non global method) print it if (t != null) { sb.Append (t.FullName.Replace('+', '.')); sb.Append ("."); } sb.Append (mb.Name); // deal with the generic portion of the method if (mb is MethodInfo && ((MethodInfo)mb).IsGenericMethod) { Type[] typars = ((MethodInfo)mb).GetGenericArguments(); sb.Append ("["); int k=0; bool fFirstTyParam = true; while (k < typars.Length) { if (fFirstTyParam == false) sb.Append (","); else fFirstTyParam = false; sb.Append (typars[k].Name); k++; } sb.Append ("]"); } // arguments printing sb.Append ("("); ParameterInfo[] pi = mb.GetParameters(); bool fFirstParam = true; for( int j=0; j < pi.Length; j++ ) { if (fFirstParam == false) sb.Append (", "); else fFirstParam = false; String typeName = "<UnknownType>"; if (pi[j].ParameterType != null) typeName = pi[j].ParameterType.Name; sb.Append (typeName + " " + pi[j].Name); } sb.Append (")"); // source location printing if (sf.GetILOffset() != -1) { // It's possible we have a debug version of an executable but no PDB. In // this case, the file name will be null. String fileName = null; try { fileName = sf.GetFileName(); } catch (SecurityException) { } if (fileName != null) { // tack on " in c:\tmp\MyFile.cs:line 5" sb.Append(' '); sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber()); } } } } if( traceFormat == TraceFormat.TrailingNewLine ) sb.Append( Environment.NewLine ); return sb.ToString(); }
// Builds a readable representation of the stack trace, specifying // the format for backwards compatibility. internal String ToString(TraceFormat traceFormat) { String word_At = "at"; String inFileLineNum = "in {0}:line {1}"; if (traceFormat != TraceFormat.NoResourceLookup) { word_At = Environment.GetResourceString("Word_At"); inFileLineNum = Environment.GetResourceString("StackTrace_InFileLineNumber"); } bool fFirstFrame = true; StringBuilder sb = new StringBuilder(255); for (int iFrameIndex = 0; iFrameIndex < m_iNumOfFrames; iFrameIndex++) { StackFrame sf = GetFrame(iFrameIndex); MethodBase mb = sf.GetMethod(); if (mb != null) { // We want a newline at the end of every line except for the last if (fFirstFrame) { fFirstFrame = false; } else { sb.Append(Environment.NewLine); } sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At); Type t = mb.DeclaringType; // if there is a type (non global method) print it if (t != null) { sb.Append(t.FullName.Replace('+', '.')); sb.Append("."); } sb.Append(mb.Name); // deal with the generic portion of the method if (mb is MethodInfo && ((MethodInfo)mb).IsGenericMethod) { Type[] typars = ((MethodInfo)mb).GetGenericArguments(); sb.Append("["); int k = 0; bool fFirstTyParam = true; while (k < typars.Length) { if (fFirstTyParam == false) { sb.Append(","); } else { fFirstTyParam = false; } sb.Append(typars[k].Name); k++; } sb.Append("]"); } // arguments printing sb.Append("("); ParameterInfo[] pi = mb.GetParameters(); bool fFirstParam = true; for (int j = 0; j < pi.Length; j++) { if (fFirstParam == false) { sb.Append(", "); } else { fFirstParam = false; } String typeName = "<UnknownType>"; if (pi[j].ParameterType != null) { typeName = pi[j].ParameterType.Name; } sb.Append(typeName + " " + pi[j].Name); } sb.Append(")"); // source location printing if (sf.GetILOffset() != -1) { // It's possible we have a debug version of an executable but no PDB. In // this case, the file name will be null. String fileName = null; try { fileName = sf.GetFileName(); } catch (SecurityException) { } if (fileName != null) { // tack on " in c:\tmp\MyFile.cs:line 5" sb.Append(' '); sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber()); } } } } if (traceFormat == TraceFormat.TrailingNewLine) { sb.Append(Environment.NewLine); } return(sb.ToString()); }
// Builds a readable representation of the stack trace, specifying // the format for backwards compatibility. internal string ToString(TraceFormat traceFormat) { bool displayFilenames = true; // we'll try, but demand may fail string word_At = "at"; string inFileLineNum = "in {0}:line {1}"; if (traceFormat != TraceFormat.NoResourceLookup) { word_At = SR.Word_At; inFileLineNum = SR.StackTrace_InFileLineNumber; } bool fFirstFrame = true; StringBuilder sb = new StringBuilder(255); for (int iFrameIndex = 0; iFrameIndex < m_iNumOfFrames; iFrameIndex++) { StackFrame sf = GetFrame(iFrameIndex); MethodBase mb = sf.GetMethod(); if (mb != null && (ShowInStackTrace(mb) || (iFrameIndex == m_iNumOfFrames - 1))) // Don't filter last frame { // We want a newline at the end of every line except for the last if (fFirstFrame) { fFirstFrame = false; } else { sb.Append(Environment.NewLine); } sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At); bool isAsync = false; Type declaringType = mb.DeclaringType; string methodName = mb.Name; bool methodChanged = false; if (declaringType != null && declaringType.IsDefined(typeof(CompilerGeneratedAttribute))) { isAsync = typeof(IAsyncStateMachine).IsAssignableFrom(declaringType); if (isAsync || typeof(IEnumerator).IsAssignableFrom(declaringType)) { methodChanged = TryResolveStateMachineMethod(ref mb, out declaringType); } } // if there is a type (non global method) print it // ResolveStateMachineMethod may have set declaringType to null if (declaringType != null) { // Append t.FullName, replacing '+' with '.' string fullName = declaringType.FullName; for (int i = 0; i < fullName.Length; i++) { char ch = fullName[i]; sb.Append(ch == '+' ? '.' : ch); } sb.Append('.'); } sb.Append(mb.Name); // deal with the generic portion of the method if (mb is MethodInfo && ((MethodInfo)mb).IsGenericMethod) { Type[] typars = ((MethodInfo)mb).GetGenericArguments(); sb.Append('['); int k = 0; bool fFirstTyParam = true; while (k < typars.Length) { if (fFirstTyParam == false) { sb.Append(','); } else { fFirstTyParam = false; } sb.Append(typars[k].Name); k++; } sb.Append(']'); } ParameterInfo[] pi = null; try { pi = mb.GetParameters(); } catch { // The parameter info cannot be loaded, so we don't // append the parameter list. } if (pi != null) { // arguments printing sb.Append('('); bool fFirstParam = true; for (int j = 0; j < pi.Length; j++) { if (fFirstParam == false) { sb.Append(", "); } else { fFirstParam = false; } string typeName = "<UnknownType>"; if (pi[j].ParameterType != null) { typeName = pi[j].ParameterType.Name; } sb.Append(typeName); sb.Append(' '); sb.Append(pi[j].Name); } sb.Append(')'); } if (methodChanged) { // Append original method name e.g. +MoveNext() sb.Append("+"); sb.Append(methodName); sb.Append("()"); } // source location printing if (displayFilenames && (sf.GetILOffset() != -1)) { // If we don't have a PDB or PDB-reading is disabled for the module, // then the file name will be null. string fileName = null; // Getting the filename from a StackFrame is a privileged operation - we won't want // to disclose full path names to arbitrarily untrusted code. Rather than just omit // this we could probably trim to just the filename so it's still mostly usefull. try { fileName = sf.GetFileName(); } catch (SecurityException) { // If the demand for displaying filenames fails, then it won't // succeed later in the loop. Avoid repeated exceptions by not trying again. displayFilenames = false; } if (fileName != null) { // tack on " in c:\tmp\MyFile.cs:line 5" sb.Append(' '); sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber()); } } if (sf.GetIsLastFrameFromForeignExceptionStackTrace() && !isAsync) // Skip EDI boundary for async { sb.Append(Environment.NewLine); sb.Append(SR.Exception_EndStackTraceFromPreviousThrow); } } } if (traceFormat == TraceFormat.TrailingNewLine) { sb.Append(Environment.NewLine); } return(sb.ToString()); }
internal String ToString (TraceFormat traceFormat) { // TODO: return ToString (); }
internal string ToString(TraceFormat traceFormat) { bool flag = true; string runtimeResourceString = "at"; string format = "in {0}:line {1}"; if (traceFormat != TraceFormat.NoResourceLookup) { runtimeResourceString = Environment.GetRuntimeResourceString("Word_At"); format = Environment.GetRuntimeResourceString("StackTrace_InFileLineNumber"); } bool flag2 = true; StringBuilder builder = new StringBuilder(0xff); for (int i = 0; i < this.m_iNumOfFrames; i++) { StackFrame frame = this.GetFrame(i); MethodBase method = frame.GetMethod(); if (method != null) { if (flag2) { flag2 = false; } else { builder.Append(Environment.NewLine); } builder.AppendFormat(CultureInfo.InvariantCulture, " {0} ", new object[] { runtimeResourceString }); Type declaringType = method.DeclaringType; if (declaringType != null) { builder.Append(declaringType.FullName.Replace('+', '.')); builder.Append("."); } builder.Append(method.Name); if ((method is MethodInfo) && ((MethodInfo) method).IsGenericMethod) { Type[] genericArguments = ((MethodInfo) method).GetGenericArguments(); builder.Append("["); int index = 0; bool flag3 = true; while (index < genericArguments.Length) { if (!flag3) { builder.Append(","); } else { flag3 = false; } builder.Append(genericArguments[index].Name); index++; } builder.Append("]"); } builder.Append("("); ParameterInfo[] parameters = method.GetParameters(); bool flag4 = true; for (int j = 0; j < parameters.Length; j++) { if (!flag4) { builder.Append(", "); } else { flag4 = false; } string name = "<UnknownType>"; if (parameters[j].ParameterType != null) { name = parameters[j].ParameterType.Name; } builder.Append(name + " " + parameters[j].Name); } builder.Append(")"); if (flag && (frame.GetILOffset() != -1)) { string fileName = null; try { fileName = frame.GetFileName(); } catch (NotSupportedException) { flag = false; } catch (SecurityException) { flag = false; } if (fileName != null) { builder.Append(' '); builder.AppendFormat(CultureInfo.InvariantCulture, format, new object[] { fileName, frame.GetFileLineNumber() }); } } } } if (traceFormat == TraceFormat.TrailingNewLine) { builder.Append(Environment.NewLine); } return builder.ToString(); }
public string Reason() => TraceFormat.DecoratorReason(target, reason);
/// <summary> /// <br>Choice function for ease of switching between the modes</br> /// <br>The functions called inside can also be called independently</br> /// <br>TraceColumnsOverlap()</br> /// <br>TraceInLineFormat()</br> /// <br>TraceInGraphFormat()</br> /// </summary> /// <param name="overlapArrays"></param> /// <param name="colDims"></param> /// <param name="formatTypes"></param> /// <param name="threshold"></param> /// <param name="aboveThreshold"></param> /// <param name="belowThreshold"></param> public static void TraceColumnsOverlap(List <double[, ]> overlapArrays, int[] colDims, TraceFormat formatTypes, double threshold, Color aboveThreshold, Color belowThreshold) //To Trace out the Columns /Overlap count { switch (formatTypes) { case TraceFormat.Text: TraceInLineFormat(overlapArrays, colDims); break; case TraceFormat.Graph: TraceInGraphFormat(overlapArrays, colDims, threshold, aboveThreshold, belowThreshold); break; case TraceFormat.Excel: TraceInExcelFormat(overlapArrays, colDims); break; default: //Debug.WriteLine($"Not A correct Trace Format! "); break; } }
internal String ToString(TraceFormat traceFormat) { // TODO: return(ToString()); }
internal void ToString(TraceFormat traceFormat, StringBuilder sb) { // Passing a default string for "at" in case SR.UsingResourceKeys() is true // as this is a special case and we don't want to have "Word_At" on stack traces. string word_At = SR.GetResourceString(nameof(SR.Word_At), defaultString: "at"); // We also want to pass in a default for inFileLineNumber. string inFileLineNum = SR.GetResourceString(nameof(SR.StackTrace_InFileLineNumber), defaultString: "in {0}:line {1}"); bool fFirstFrame = true; for (int iFrameIndex = 0; iFrameIndex < _numOfFrames; iFrameIndex++) { StackFrame?sf = GetFrame(iFrameIndex); MethodBase?mb = sf?.GetMethod(); if (mb != null && (ShowInStackTrace(mb) || (iFrameIndex == _numOfFrames - 1))) // Don't filter last frame { // We want a newline at the end of every line except for the last if (fFirstFrame) { fFirstFrame = false; } else { sb.AppendLine(); } sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At); bool isAsync = false; Type? declaringType = mb.DeclaringType; string methodName = mb.Name; bool methodChanged = false; if (declaringType != null && declaringType.IsDefined(typeof(CompilerGeneratedAttribute), inherit: false)) { isAsync = typeof(IAsyncStateMachine).IsAssignableFrom(declaringType); if (isAsync || typeof(IEnumerator).IsAssignableFrom(declaringType)) { methodChanged = TryResolveStateMachineMethod(ref mb, out declaringType); } } // if there is a type (non global method) print it // ResolveStateMachineMethod may have set declaringType to null if (declaringType != null) { // Append t.FullName, replacing '+' with '.' string fullName = declaringType.FullName !; for (int i = 0; i < fullName.Length; i++) { char ch = fullName[i]; sb.Append(ch == '+' ? '.' : ch); } sb.Append('.'); } sb.Append(mb.Name); // deal with the generic portion of the method if (mb is MethodInfo mi && mi.IsGenericMethod) { Type[] typars = mi.GetGenericArguments(); sb.Append('['); int k = 0; bool fFirstTyParam = true; while (k < typars.Length) { if (!fFirstTyParam) { sb.Append(','); } else { fFirstTyParam = false; } sb.Append(typars[k].Name); k++; } sb.Append(']'); } ParameterInfo[]? pi = null; try { pi = mb.GetParameters(); } catch { // The parameter info cannot be loaded, so we don't // append the parameter list. } if (pi != null) { // arguments printing sb.Append('('); bool fFirstParam = true; for (int j = 0; j < pi.Length; j++) { if (!fFirstParam) { sb.Append(", "); } else { fFirstParam = false; } string typeName = "<UnknownType>"; if (pi[j].ParameterType != null) { typeName = pi[j].ParameterType.Name; } sb.Append(typeName); sb.Append(' '); sb.Append(pi[j].Name); } sb.Append(')'); } if (methodChanged) { // Append original method name e.g. +MoveNext() sb.Append('+'); sb.Append(methodName); sb.Append('(').Append(')'); } // source location printing if (sf !.GetILOffset() != -1) { // If we don't have a PDB or PDB-reading is disabled for the module, // then the file name will be null. string?fileName = sf.GetFileName(); if (fileName != null) { // tack on " in c:\tmp\MyFile.cs:line 5" sb.Append(' '); sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber()); } } // Skip EDI boundary for async if (sf.IsLastFrameFromForeignExceptionStackTrace && !isAsync) { sb.AppendLine(); // Passing default for Exception_EndStackTraceFromPreviousThrow in case SR.UsingResourceKeys is set. sb.Append(SR.GetResourceString(nameof(SR.Exception_EndStackTraceFromPreviousThrow), defaultString: "--- End of stack trace from previous location ---")); } } } if (traceFormat == TraceFormat.TrailingNewLine) { sb.AppendLine(); } }
public static string ExceptionToString(Exception ex, bool needFileLineInfo, TraceFormat tf) { bool isHtml = (tf == TraceFormat.Html); string newLine = isHtml ? "<br />" + Environment.NewLine : Environment.NewLine; var builder = new StringBuilder(0xff); if (isHtml) { var exText = (ex.GetType().Name + ": " + ex.Message).Replace("\r\n", "<br />"); builder.Append("<hr/>" + exText + "<hr/>"); } if (isHtml) { builder.Append("<span style=\"font-family: Courier New; font-size: 10pt;\">"); } builder.Append(getText(isHtml, GetClassName(ex))); string message = ex.Message; if (!string.IsNullOrEmpty(message)) { builder.Append(": "); builder.Append(getText(isHtml, message)); } if (ex != null) { builder.Append(newLine); StackTrace stackTrace; // If use stable version. if (UseStableExceptionVersion) { // Stable version. stackTrace = new StackTrace(ex, needFileLineInfo); if (stackTrace != null) { builder.Append(newLine); builder.Append(TraceToString(stackTrace, tf)); } } else { // Unstable version // Get full stack trace. stackTrace = new StackTrace(needFileLineInfo); int startFrameIndex = 0; if (ex != null) { var exTrace = new StackTrace(ex, needFileLineInfo); if (exTrace.FrameCount > 0) { var method = exTrace.GetFrame(0).GetMethod(); if (method != null) { for (int i = 0; i < stackTrace.FrameCount; i++) { var m2 = stackTrace.GetFrame(i).GetMethod(); if (m2 != null && m2.Equals(method)) { startFrameIndex = i; break; } } } } } builder.Append(newLine); builder.Append(TraceToString(stackTrace, tf, startFrameIndex)); } if (ex.InnerException != null) { builder.Append(getText(isHtml, " ---> ")); builder.Append(ExceptionToString(ex.InnerException, needFileLineInfo, tf)); builder.Append(newLine); } } if (isHtml) { builder.Append("</span>"); } return(builder.ToString()); }