public CodeDescriptor(int offset, System.Reflection.MethodBase method) { Offset = offset; this.DeclaringType = method.DeclaringType.FullName; this.Method = method.ToString(); this.Assembly = method.DeclaringType.Assembly.FullName; }
public Frame(TraceSource src, string frameName) { source = src; if (frameName == null) { System.Reflection.MethodBase m = (new StackFrame(2)).GetMethod(); frameName = m.ToString(); } src.TraceEvent(TraceEventType.Start, 0, frameName); }
/// <summary> /// Converts the IL op to a human-readable representation. /// </summary> /// <remarks> /// Uses the name of the IL op from the ILOp.OpCodes enumerable or the name of the /// custom op if it is a custom IL op. /// </remarks> /// <returns>The human-readable representation of the IL op.</returns> public override string ToString() { if (this.GetType().Name != "ILOp") { return(this.GetType().Name + (MethodToCall == null ? "" : " - " + MethodToCall.ToString())); } else { return(Enum.GetName(typeof(ILOp.OpCodes), (ILOp.OpCodes)opCode.Value) + (MethodToCall == null ? "" : " - " + MethodToCall.ToString())); } }
public StackInfo() { StackTrace st = new StackTrace(); StackFrame sf = new StackFrame(4, true); if (sf == null) { return; } try { int p; LineNumber = sf.GetFileLineNumber(); System.Reflection.MethodBase method = sf.GetMethod(); if (method != null) { if (method.ReflectedType != null) { ObjectName = method.ReflectedType.ToString(); } else { ObjectName = "global"; } MethodName = method.ToString(); p = MethodName.IndexOf(" ") + 1; MethodName = MethodName.Substring(p, MethodName.Length - p); } FileName = sf.GetFileName(); if (FileName != null) { p = FileName.LastIndexOf(@"\") + 1; FileName = FileName.Substring(p, FileName.Length - p); } } catch { } }
/// <summary> /// Description: Crea o añade cada una de las excepciones al Log /// </summary> /// <param name="func"></param> /// <param name="p2"></param> /// <param name="p3"></param> /// <param name="p4"></param> /// <param name="p5"></param> /// <param name="methodBase"></param> private static void LogFile(Func <string> i_func, int i_p2, string i_p3, string i_p4, string i_p5, System.Reflection.MethodBase i_methodBase) { StreamWriter log; if (!File.Exists("logfile.txt")) { log = new StreamWriter("logfile.txt"); } else { log = File.AppendText("logfile.txt"); } // Write to the file: log.WriteLine("Data Time:" + DateTime.Now); log.WriteLine("Exception Data:" + i_func); log.WriteLine("HResult:" + i_p2); log.WriteLine("Message:" + i_p3); log.WriteLine("Source:" + i_p4); log.WriteLine("StackTrace:" + i_p5); log.WriteLine("Form Name:" + i_methodBase.ToString()); log.Close(); }
public static void CaptureStackFrames(object exception) { var frames = new List <CLSStackFrame>(); Exception ex = exception as Exception; Action <StackTrace> frameWalker = (st) => { for (int i = 0; i < st.FrameCount; i++) { StackFrame sf = st.GetFrame(i); string filename = sf.GetFileName(); System.Reflection.MethodBase method = sf.GetMethod(); string methodName = ""; if (method != null) { var tokens = method.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Count() > 1) { methodName = tokens.Skip(1).Aggregate((a, b) => a + " " + b); } else { methodName = method.ToString(); } } frames.Add(new CLSStackFrame() { FileName = filename ?? (method != null ? method.DeclaringType.Name + ".cs" : "uknown"), LineNumber = (uint)sf.GetFileLineNumber(), Library = Library, Symbol = method != null ? method.DeclaringType.FullName + "." + methodName : "wrapper_managed_to_native" }); } }; if (ex != null) { //get traces from excetion dispath info - their are not included in StackTrace on mono StackTrace[] traces = null; var fi = typeof(Exception).GetField("captured_traces", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); if (fi != null) { traces = fi.GetValue(ex) as StackTrace[]; } if (traces != null) { foreach (var st in traces) { frameWalker(st); } } frameWalker(new StackTrace(ex, true)); Crashlytics.SharedInstance.RecordCustomExceptionName(ex.GetType().Name, ex.Message, frames.Cast <NSObject>().ToArray()); } }
public override void CompileTimeInitialize(System.Reflection.MethodBase method) { methodName = method.ToString(); }
public static void logResults(System.Reflection.MethodBase method, Results result, string message) { string stringMethod = ""; bool isNullMethod = true; if (method != null) { stringMethod = method.ToString(); isNullMethod = false; } var sb = new StringBuilder(); string date = DateTime.Now.ToString(); int index = date.IndexOf(" "); string subString = date.Substring(0, index); string nwDate = Regex.Replace(subString, "/", ""); logFileName = "WebsiteRegressionProduction_TestCycle." + nwDate; string currentLogFile = logFileLocation + @"\" + logFileName; try { if (!Directory.Exists(logFileLocation)) { Directory.CreateDirectory(logFileLocation); } if (!File.Exists(currentLogFile)) { File.WriteAllText(currentLogFile, "DATE-TIME\t\t\t\tACTION\t\t\tTEST CLASS\t\t\tTEST NAME\t\t\t\t\t\tTEST STATUS\t\tERROR MESSAGES\n\n", Encoding.ASCII); } if (!isNullMethod) { if (stringMethod.Contains("ConfigurationFiles")) { sb.Append("\n\n\n"); } } sb.Append(String.Format("{0} : Test Executed: {1} : {2} : {3} : {4}\n\n", DateTime.Now.ToString(), method.ReflectedType.Name, method, result, message)); using (var stream = File.AppendText(currentLogFile)) { stream.Write(sb.ToString()); } } catch (IOException e) { Console.WriteLine(e.Message); Console.Read(); } catch (Exception e) { if (!Directory.Exists(logFileLocation)) { Directory.CreateDirectory(logFileLocation); } if (!File.Exists(currentLogFile)) { File.WriteAllText(currentLogFile, "DATE-TIME\t\t\t\tACTION\t\t\tTEST CLASS\t\t\tTEST NAME\t\t\t\t\t\tTEST STATUS\t\tERROR MESSAGES\n\n", Encoding.ASCII); } sb.Append("Exception Occured in the Logger: " + e.Message); using (var stream = File.AppendText(currentLogFile)) { stream.Write(sb.ToString()); } } }