在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();

}

 

最新文章

  1. 及时取消代码中的AsyncTask
  2. ImageView cannot be resolved to a type
  3. ngui中 代码调用按钮事件(后来改成了按钮绑定键盘..)
  4. 【Linux】将Oracle安装目录从根目录下迁移到逻辑卷
  5. NHibernate 基本配置 (第一篇)
  6. Hibernate映射多对多双向关联关系(小案例)
  7. LeetCode Binary Search Tree Iterator
  8. WordPress 撰写文章页面显示所有标签
  9. poj 3273 Monthly Expense(贪心+二分)
  10. Windows下使用ODBC API访问数据库之关键
  11. SignalR在Xamarin Android中的使用
  12. Spring中的DataBinding(一)
  13. A. Anton and Letters
  14. 数学之路-python计算实战(15)-机器视觉-滤波去噪(归一化块滤波)
  15. React源码学习——ReactClass
  16. 一个Web 持续集成工作实践
  17. Linux基本命令整理_sheng
  18. Celery(四)定时任务
  19. 在编写Arcgis Engine 过程中对于接口引用和实现过程过产生的感悟
  20. 2018-2019-2 网络对抗技术 20165206 Exp4 恶意代码分析

热门文章

  1. selenium+plantomJS
  2. visual studio snippet备忘
  3. windows 计算器
  4. HIVE的安装步骤及遇到的问题及解决方法
  5. selenium 无头浏览器headless browser
  6. px2rem-loader(Vue:将px转化为rem,适配移动端)
  7. csp-s模拟测试92
  8. flutter 死亡红屏 隐藏
  9. word 文献标题自动编号
  10. Python3 From Zero——{最初的意识:003~数字、日期、时间}