VS输出窗口(output view)的小技巧--文件行号字符定位
2010-11-12 10:57
483 查看
在我们的调试输出到VS输出窗口的信息,有时候我们想要鼠标点击就定位该该文件,改行,甚至该列。在强大的VS工具中已经给我们提供了这个功能,我们只需要把输出到输出窗
口的字符串就是一定的格式化就可以了。c#在VS输出窗口格式为:
文件名称(行号,列号):消息信息。
比如我 test.cs(100,78):消息信息。就是对应我们的test.cs文件的100行78个字符。
在这里我写了一个简单异常输出信息的扩展类。
代码具体如下:
代码
public class OutPutExceptionEx
{
public static void WriteLine(string message, Exception ex)
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(ex, true);
System.Diagnostics.StackFrame frm = st.GetFrame(0);
if (frm != null)
{
System.Diagnostics.Debug.WriteLine(string.Format("{0}({1},{2}):{3})", frm.GetFileName(), frm.GetFileLineNumber(), frm.GetFileColumnNumber(),
message));
}
}
public static void WriteLine(Exception ex)
{
WriteLine(ex.Message, ex);
}
public static void Write(string message, Exception ex)
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(ex, true);
System.Diagnostics.StackFrame frm = st.GetFrame(0);
if (frm != null)
{
System.Diagnostics.Debug.Write(string.Format("{0}({1},{2}):{3})", frm.GetFileName(), frm.GetFileLineNumber(), frm.GetFileColumnNumber(),
message));
}
}
public static void Write(Exception ex)
{
Write(ex.Message,ex);
}
}
//测试
class Program
{
static void Main(string[] args)
{
try
{
throw new Exception("这个发生了一个错误!");
}
catch (Exception ex)
{
OutPutExceptionEx.Write(ex);
}
Console.WriteLine("ok");
Console.Read();
}
}
图片效果:
![](http://images.cnblogs.com/cnblogs_com/whitewolf/201011121051.jpg)
2:
口的字符串就是一定的格式化就可以了。c#在VS输出窗口格式为:
文件名称(行号,列号):消息信息。
比如我 test.cs(100,78):消息信息。就是对应我们的test.cs文件的100行78个字符。
在这里我写了一个简单异常输出信息的扩展类。
代码具体如下:
代码
public class OutPutExceptionEx
{
public static void WriteLine(string message, Exception ex)
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(ex, true);
System.Diagnostics.StackFrame frm = st.GetFrame(0);
if (frm != null)
{
System.Diagnostics.Debug.WriteLine(string.Format("{0}({1},{2}):{3})", frm.GetFileName(), frm.GetFileLineNumber(), frm.GetFileColumnNumber(),
message));
}
}
public static void WriteLine(Exception ex)
{
WriteLine(ex.Message, ex);
}
public static void Write(string message, Exception ex)
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(ex, true);
System.Diagnostics.StackFrame frm = st.GetFrame(0);
if (frm != null)
{
System.Diagnostics.Debug.Write(string.Format("{0}({1},{2}):{3})", frm.GetFileName(), frm.GetFileLineNumber(), frm.GetFileColumnNumber(),
message));
}
}
public static void Write(Exception ex)
{
Write(ex.Message,ex);
}
}
//测试
class Program
{
static void Main(string[] args)
{
try
{
throw new Exception("这个发生了一个错误!");
}
catch (Exception ex)
{
OutPutExceptionEx.Write(ex);
}
Console.WriteLine("ok");
Console.Read();
}
}
图片效果:
![](http://images.cnblogs.com/cnblogs_com/whitewolf/201011121051.jpg)
2:
![](http://images.cnblogs.com/cnblogs_com/whitewolf/2010111210512.jpg)
相关文章推荐
- VS输出窗口(output view)的小技巧--文件行号字符定位
- VC++小技巧-Output窗口输出定位
- VC++小技巧-Output窗口输出定位 .
- debugview + outputdebugstring 调试程序 同时也可以输出调试日志文件
- 向VS的Output窗口输出调试信息
- vs2012 输出窗口报错 “无法查找或打开 PDB 文件”
- ios8 定位授权问题 (plist文件设置字段 手动调用授权仍然不能弹出alertview窗口)
- vs2013输出-1.#INF等特殊字符的文件读取
- log4net日志输出配置即输出到文件又输出到visual studio的output窗口
- 实现一个简单的log类,目标:能够在VS的输出窗口定位调用点
- Mac计算机上面的类似于VS中的output信息输出窗口
- 用python比较两个文件中内容的不同之处, 并输出行号和内容.
- 用对话框作为主窗口;IDD_FORMVIEW资源文件;
- vs2013 设置不显示输出窗口
- Android中将布局文件/View添加至窗口过程分析 ---- 从setContentView()谈起
- makefile有关问题,想像vs一样将目标文件,输出文件存放在指定文件夹,而不是在源文件的目录
- 获取exe文件窗口抓图,将memo转化为JPG输出
- C#调试中,在VS的输出窗口或即时窗口显示消息
- 使用ifstream的get()函数读取文件中的字符后输出时,最后一个字符多输出一次
- PL/SQL 中 dbms_output.put_line 输出字符长度限制的问题