public static string ToHtmlTable(this Exception ex) { var sb = new StringBuilder("<table><caption>Debug Info</caption><tbody>"); var exStackTrace = new StackTrace(ex, true).GetFrame(0); sb.AppendLine(HtmlConstants.ROW_WITH_COLSPAN_HTML("StackTrace")); sb.AppendLine(HtmlConstants.ROW_HTML("ExGetFileName", exStackTrace.GetFileName())); sb.AppendLine(HtmlConstants.ROW_HTML("ExGetType", exStackTrace.GetType().ToString())); sb.AppendLine(HtmlConstants.ROW_HTML("ExGetMethod", exStackTrace.GetMethod().ToString())); sb.AppendLine(HtmlConstants.ROW_HTML("ExGetFileLineNumber", exStackTrace.GetFileLineNumber().ToString())); sb.AppendLine(HtmlConstants.ROW_HTML("ExGetFileColumnNumber", exStackTrace.GetFileColumnNumber().ToString())); var baseEx = ex.GetBaseException(); sb.AppendLine(HtmlConstants.ROW_WITH_COLSPAN_HTML("BaseException")); sb.AppendLine(HtmlConstants.ROW_HTML("Message", baseEx.Message)); sb.AppendLine(HtmlConstants.ROW_HTML("Data", baseEx.Data.ToString())); sb.AppendLine(HtmlConstants.ROW_HTML("Source", baseEx.Source)); sb.AppendLine(HtmlConstants.ROW_HTML("Last StackTrace", (" " + ex.StackTrace).Replace(" at ", "<br/>at "))); sb.AppendLine(HtmlConstants.ROW_HTML("Base StackTrace", (" " + baseEx.StackTrace).Replace(" at ", "<br/>at "))); var BaseStackTrace = new StackTrace(baseEx, true).GetFrame(0); sb.AppendLine(HtmlConstants.ROW_WITH_COLSPAN_HTML("BaseStackTrace")); sb.AppendLine(HtmlConstants.ROW_HTML("BaseGetFileName", BaseStackTrace.GetFileName())); sb.AppendLine(HtmlConstants.ROW_HTML("BaseGetType", BaseStackTrace.GetType().ToString())); sb.AppendLine(HtmlConstants.ROW_HTML("BaseGetMethod", BaseStackTrace.GetMethod().ToString())); sb.AppendLine(HtmlConstants.ROW_HTML("BaseGetFileLineNumber", BaseStackTrace.GetFileLineNumber().ToString())); sb.AppendLine(HtmlConstants.ROW_HTML("BaseGetFileColumnNumber", BaseStackTrace.GetFileColumnNumber().ToString())); sb.AppendLine("</tbody></table>"); return(sb.ToString()); }
public static void LogExceptionLineNumber(this Logger logger, Exception ex) { var stackFrame = new StackTrace().GetFrame(1); int columnNumber = stackFrame.GetFileColumnNumber(); logger.Fatal(String.Format("{0} occured at line {1}.", ex.GetType().Name, columnNumber)); }
public ErrorHandlingModel TratarErro(Exception ex) { var frame = new StackFrame(); try { frame = new StackTrace(ex, true) .GetFrames() .First(f => f.GetMethod().DeclaringType.Name.Contains("Data.Repository") || f.GetMethod().DeclaringType.Name.Contains("DataStopCommand") || f.GetMethod().DeclaringType.Name.Contains("String") || f.GetMethod().DeclaringType.Name.Contains("DateTime")); } catch (Exception) { frame = new StackTrace(ex, true).GetFrames().FirstOrDefault(); } var result = JsonConvert.SerializeObject(new { Message = "Problemas no sistema. Entre em contato com o administrador do sistema.", Error = new { Text = ex.Message, Method = (frame.GetMethod().DeclaringType == null ? "" : frame.GetMethod().DeclaringType.Name) + "." + frame.GetMethod().Name, Line = frame.GetFileLineNumber(), Column = frame.GetFileColumnNumber() + "." + (int)HttpStatusCode.BadRequest } }); return(new ErrorHandlingModel((int)HttpStatusCode.BadRequest, result)); }
public void LogErrorFromException(Exception exception) { if (UIThreadId == Thread.CurrentThread.ManagedThreadId) #pragma warning disable 618 { Log.LogErrorFromException(exception); } #pragma warning restore 618 StackFrame exceptionFrame = null; try { exceptionFrame = new StackTrace(exception, true)?.GetFrames()?.FirstOrDefault(); } catch { } lock (errorMessageQueue.SyncRoot) { errorMessageQueue.Enqueue(new BuildErrorEventArgs( subcategory: null, code: null, file: exceptionFrame?.GetFileName(), lineNumber: exceptionFrame?.GetFileLineNumber() ?? 0, columnNumber: exceptionFrame?.GetFileColumnNumber() ?? 0, endLineNumber: 0, endColumnNumber: 0, message: exception.Message, helpKeyword: null, senderName: null )); lock (_eventlock) { if (isRunning) { errorDataAvailable.Set(); } } } }
public static string StackTraceDemo2(string author, string sqlDesc) { StackFrame stackFrame = new StackTrace(true).GetFrame(1); int fileColumnNumber = stackFrame.GetFileColumnNumber(); int fileLineNumber = stackFrame.GetFileLineNumber(); string fileName = stackFrame.GetFileName(); int ilOffset = stackFrame.GetILOffset(); MethodBase mb = stackFrame.GetMethod(); int no = stackFrame.GetNativeOffset(); return(string.Format("/*Author:{0}/For:{1}/File:///{2}/Fun:{3}*/", author, sqlDesc, stackFrame.GetFileName(), stackFrame.GetMethod().Name)); }
public static void WriteLocation() { var stackFrame = new StackTrace(2, true).GetFrame(0); var file = stackFrame.GetFileName(); var line = stackFrame.GetFileLineNumber(); var column = stackFrame.GetFileColumnNumber(); if (!string.IsNullOrEmpty(file)) { Console.WriteLine($" at: {file}:{line}:{column}"); } else { Console.WriteLine($" at: unavailable - compile and run in debug mode to have this"); } }
private static AppError ConvertToAppError(Exception e) { var frame = new StackTrace(e, true).GetFrame(0); return(new AppError { Kind = "C#", Type = e.GetType().Name, LineNumber = frame?.GetFileLineNumber() ?? 0, ColumnNumber = frame?.GetFileColumnNumber() ?? 0, FileName = frame?.GetFileName() ?? string.Empty, Message = e.Message, StackTrace = e.StackTrace, TimeStamp = DateTime.Now }); }
public string GetInfo() { string message = Message; if (TrackLocation) { var frame = new StackTrace(this, true).GetFrame(0); message += " (from " + Path.GetFileName(frame.GetFileName()) + " at line " + frame.GetFileLineNumber() + ", column " + frame.GetFileColumnNumber() + ")"; } return(message); }
/// <summary> /// 获取日志上改变的文件路径 /// </summary> /// <param name="path">本地路径</param> /// <param name="version">某个具体版本</param> /// <param name="action">操作</param> /// <returns></returns> public static List <string> GetLogFPath(string path, int version, string action) { List <string> paths = new List <string>(); using (SvnClient svn = new SvnClient()) { try { Collection <SvnLogEventArgs> logItems = new Collection <SvnLogEventArgs>(); svn.GetLog(path, out logItems); //过滤版本 //logItems = (Collection<SvnLogEventArgs>)logItems.Where(o => o.Revision == version); foreach (var log in logItems) { foreach (SvnChangeItem svnChangeItem in (Collection <SvnChangeItem>)log.ChangedPaths) { if (svnChangeItem.Action.ToString() == action && log.Revision == version) { paths.Add(svnChangeItem.Path); } } } } catch (Exception ex) { operSVN.lastErrMsg = ex.Message; StackFrame frame = new StackTrace(new StackFrame(true)).GetFrame(0); operSVN.wlog(ex.Message, frame.GetFileName() + (object)"|" + (string)(object)frame.GetMethod() + "|" + (string)(object)frame.GetFileLineNumber() + "|" + (string)(object)frame.GetFileColumnNumber()); return(null); } } return(paths); }
/// <summary> /// 更新 /// </summary> /// <param name="path"></param> /// <returns></returns> public static bool Update(string path) { bool result = true; using (SvnClient svn = new SvnClient()) { try { result = svn.Update(path); } catch (Exception ex) { operSVN.lastErrMsg = ex.Message; StackFrame frame = new StackTrace(new StackFrame(true)).GetFrame(0); operSVN.wlog(ex.Message, frame.GetFileName() + (object)"|" + (string)(object)frame.GetMethod() + "|" + (string)(object)frame.GetFileLineNumber() + "|" + (string)(object)frame.GetFileColumnNumber()); return(false); } } if (operSVN.update(path)) { return(true); } return(result); }
/// <summary> /// 获取日志上改变的文件路径 /// </summary> /// <param name="path">本地路径</param> /// <param name="startVersion">开始版本</param> /// <param name="endVersion">结束版本</param> /// <returns></returns> public static Dictionary <string, int> GetLogFPath(string path, int startVersion, int endVersion, List <string> formats, out Dictionary <string, string> logaction) { logaction = new Dictionary <string, string>(); Dictionary <string, int> paths = new Dictionary <string, int>(); using (SvnClient svn = new SvnClient()) { try { //拿到所有的日志 Collection <SvnLogEventArgs> logItems = new Collection <SvnLogEventArgs>(); svn.GetLog(path, out logItems); foreach (var log in logItems) { foreach (SvnChangeItem svnChangeItem in (Collection <SvnChangeItem>)log.ChangedPaths) { //过滤版本 if ((log.Revision >= startVersion && log.Revision <= endVersion)) { foreach (var temp in formats) { if (Path.GetExtension(svnChangeItem.Path.ToLower()).Contains(temp.ToLower())) { if (paths.ContainsKey(svnChangeItem.Path)) { if (paths[svnChangeItem.Path] < (int)log.Revision) { paths.Remove(svnChangeItem.Path); } else { continue; } } else if (svnChangeItem.Action.ToString().Equals("delete", StringComparison.OrdinalIgnoreCase)) { continue; } paths.Add(svnChangeItem.Path, (int)log.Revision); logaction.Add(svnChangeItem.Path, svnChangeItem.Action.ToString()); } } } } } } catch (Exception ex) { operSVN.lastErrMsg = ex.Message; StackFrame frame = new StackTrace(new StackFrame(true)).GetFrame(0); operSVN.wlog(ex.Message, frame.GetFileName() + "|" + frame.GetMethod() + "|" + frame.GetFileLineNumber() + "|" + frame.GetFileColumnNumber() + "|"); return(null); } } return(paths); }
// A dynamic script call handler. Any call in TIScript to function 'view.Host_HelloWorld()' with invoke this method // Notice that signature of these handlers is always the same // (Hint: install OmniCode snippets which adds the 'ssh' snippet to C# editor so you can easily declare 'Siter Handler' methods) // (see: https://github.com/MISoftware/OmniCode-Snippets) public bool Host_HelloSciter(SciterElement el, SciterValue[] args, out SciterValue result) { var stackFrame = new StackTrace(true).GetFrame(0); //.GetFileName(); result = SciterValue.Create($"<h2>Hello Sciter from C#!</h2><code>Method: {stackFrame.GetMethod().Name}<br/>File: <a href=\"{new Uri(stackFrame.GetFileName()).AbsoluteUri}\">{Path.GetFileName(stackFrame.GetFileName())}</a><br/>Line: {stackFrame.GetFileLineNumber()}<br/>Column: {stackFrame.GetFileColumnNumber()}</code>"); return(true); }
public static void StackTrace(Exception ex) { Write(ex.Message); var frame = new StackTrace(ex, true).GetFrame(0); Write(string.Format("FileName: {0} LineNumber: {1} ColumnNumber: {2} Method: {3} Class: {4} ", frame.GetFileName(), frame.GetFileLineNumber(), frame.GetFileColumnNumber(), frame.GetMethod(), frame.GetMethod().DeclaringType)); }
public static OutputModel GetLofInfo(string localPath) { OutputModel output = new OutputModel(); List <String> result = new List <string>(); using (SvnClient svn = new SvnClient()) { try { //拿到所有的日志 Collection <SvnLogEventArgs> logItems = new Collection <SvnLogEventArgs>(); svn.GetLog(localPath, out logItems); result.Add(logItems[0].LogMessage); result.Add(logItems[0].Revision.ToString()); output.Status = "1"; output.Data = result; } catch (Exception ex) { operSVN.lastErrMsg = ex.Message; StackFrame frame = new StackTrace(new StackFrame(true)).GetFrame(0); operSVN.wlog(ex.Message, frame.GetFileName() + "|" + frame.GetMethod() + "|" + frame.GetFileLineNumber() + "|" + frame.GetFileColumnNumber() + "|"); output.Status = "-1"; output.Message = ex.Message; return(output); } return(output); } }
static void Main(string[] args) { try { string filename; if (args.Length > 0) { filename = args[0]; } else { filename = @"C:\Users\3stra\Dropbox\Guy\BridgeHands\hand.pbn"; } Console.WriteLine("Input the card order: type \r\n S for SHCD\r\n H for HSDC\r\n " + "D for DSHC\r\n C for CHSD\r\n SHDC or 'Enter' for standard input order (no reordring will be perfomed)\r\n" + "HH for HSCD, CC for CDSH (special ordring)\r\n" + "If hand is in full Notation unsorted (e.g. AsKsQhJcTd) press enter"); string order = Console.ReadLine().ToUpper(); var lines = from line in File.ReadLines(filename) //where line.Contains("[Deal ") select new { Line = line }; string newFile = filename.Substring(0, filename.Length - 4) + ".PRC.pbn"; using (StreamWriter sw = File.CreateText(newFile)) { foreach (var l in lines) { if (l.Line.Contains("[Deal ")) { string s = FixDeal(l.Line, order); Console.WriteLine("Pre Procesed Deal: " + l.Line); Console.WriteLine(" Post Process: " + s); sw.WriteLine(s); } else { Console.WriteLine(l.Line); sw.WriteLine(l.Line); } } } Console.WriteLine("press w to open in wBridge5"); string ss = Console.ReadLine(); if (ss.ToUpper() == "W") { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = @"C:\wbridge5\Wbridge5.exe"; startInfo.Arguments = "\"" + newFile + "\""; Process.Start(startInfo); } } catch (Exception ex) { //var st = new StackTrace(ex, true); // Get the top stack frame var frame = new StackTrace(ex, true).GetFrame(0); // Get the line number from the stack frame //var line = frame.GetFileLineNumber(); //var col = frame.GetFileColumnNumber(); Alert(ConsoleColor.Red, ex.Message + "\t line: " + frame.GetFileLineNumber() + "\t col: " + frame.GetFileColumnNumber()); Console.ReadLine(); } }
private static string CatchError(Exception error) { if (error == null) { return(string.Empty); } var i = 1; var fullText = new StringWriter(); var frame = new StackTrace(error, true).GetFrame(0); fullText.WriteLine($"Exception {i++:D2} ==================================="); fullText.WriteLine($"Type: {error.GetType()}"); fullText.WriteLine($"Source: {error.TargetSite?.DeclaringType?.AssemblyQualifiedName}"); fullText.WriteLine($"Message: {error.Message}"); fullText.WriteLine($"Trace: {error.StackTrace}"); if (frame != null) { fullText.WriteLine($"Location: {frame.GetFileName()}"); fullText.WriteLine($"Method: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})"); } var exception = error.InnerException; while (exception != null) { frame = new StackTrace(exception, true).GetFrame(0); fullText.WriteLine($"\tException {i++:D2} inner --------------------------"); fullText.WriteLine($"\tType: {exception.GetType()}"); fullText.WriteLine($"\tSource: {exception.TargetSite?.DeclaringType?.AssemblyQualifiedName}"); fullText.WriteLine($"\tMessage: {exception.Message}"); fullText.WriteLine($"\tTrace: {exception.StackTrace}"); if (frame != null) { fullText.WriteLine($"\tLocation: {frame.GetFileName()}"); fullText.WriteLine($"\tMethod: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})"); } exception = exception.InnerException; } return(fullText.ToString()); }
private static string CatchErrors(Exception error) { if (error == null) { return(string.Empty); } var i = 1; var fullText = new StringWriter(); var frame = new StackTrace(error, true).GetFrame(0); fullText.WriteLine("<div style='padding 10px; margin 0 0 30px 0;'>"); fullText.WriteLine($"<h3>Exception {i:D2} ===================================</h3>"); fullText.WriteLine($"Type: {error.GetType()}"); fullText.WriteLine($"<br />Source: {error.TargetSite?.DeclaringType?.AssemblyQualifiedName}"); fullText.WriteLine($"<br />Message: {error.Message}"); fullText.WriteLine($"<br />Trace: {error.StackTrace}"); fullText.WriteLine($"<br />Location: {frame.GetFileName()}"); fullText.WriteLine($"<br />Method: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})"); fullText.WriteLine("</div>"); var exception = error.InnerException; while (exception != null) { frame = new StackTrace(exception, true).GetFrame(0); fullText.WriteLine("<div style='padding 10px; margin 0 0 30px 30px;'>"); fullText.WriteLine($"<h4>Exception {i++:D2} inner --------------------------</h4>"); fullText.WriteLine($"Type: {exception.GetType()}"); fullText.WriteLine($"<br />Source: {exception.TargetSite?.DeclaringType?.AssemblyQualifiedName}"); fullText.WriteLine($"<br />Message: {exception.Message}"); fullText.WriteLine($"<br />Location: {frame.GetFileName()}"); fullText.WriteLine($"<br />Method: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})"); fullText.WriteLine("</div>"); exception = exception.InnerException; } return(fullText.ToString()); }