C#获取当前运行的源代码的文件名和当前源代码的行数的方法
2024-09-05 03:44:44
在C#中记录日志时,为了以后查找错误或者跟踪的方便,最好能记录下出错的源代码的文件名和出错的源代码的行数。
这2个方法如下:
/// <summary>
/// 取得当前源码的哪一行
/// </summary>
/// <returns></returns>
public static int GetLineNum()
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, true);
return st.GetFrame(0).GetFileLineNumber();
}
/// <summary>
/// 取当前源码的源文件名
/// </summary>
/// <returns></returns>
public static string GetCurSourceFileName()
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, true);
return st.GetFrame(0).GetFileName();
}
最新文章
- 及时取消代码中的AsyncTask
- ImageView cannot be resolved to a type
- ngui中 代码调用按钮事件(后来改成了按钮绑定键盘..)
- 【Linux】将Oracle安装目录从根目录下迁移到逻辑卷
- NHibernate 基本配置 (第一篇)
- Hibernate映射多对多双向关联关系(小案例)
- LeetCode Binary Search Tree Iterator
- WordPress 撰写文章页面显示所有标签
- poj 3273 Monthly Expense(贪心+二分)
- Windows下使用ODBC API访问数据库之关键
- SignalR在Xamarin Android中的使用
- Spring中的DataBinding(一)
- A. Anton and Letters
- 数学之路-python计算实战(15)-机器视觉-滤波去噪(归一化块滤波)
- React源码学习——ReactClass
- 一个Web 持续集成工作实践
- Linux基本命令整理_sheng
- Celery(四)定时任务
- 在编写Arcgis Engine 过程中对于接口引用和实现过程过产生的感悟
- 2018-2019-2 网络对抗技术 20165206 Exp4 恶意代码分析