异常日志记录
来源:互联网 发布:mac配套手绘板 编辑:程序博客网 时间:2024/06/07 21:23
在程序运行时,出现异常的时候,常常需要氢异常信息记录下来,以便查看分析异常,准确定位 ,以下是自己写的 封装好公用 异常方法
public static void ErrorLog(Exception ex) { string FilePath = "/ErrorLog.txt"; StringBuilder msg = new StringBuilder (); msg.Append("*************************************** \n"); msg.AppendFormat(" 异常发生时间: {0} \n",DateTime.Now); msg.AppendFormat(" 异常类型: {0} \n",ex.HResult); msg.AppendFormat(" 导致当前异常的 Exception 实例: {0} \n",ex.InnerException); msg.AppendFormat(" 导致异常的应用程序或对象的名称: {0} \n",ex.Source); msg.AppendFormat(" 引发异常的方法: {0} \n",ex.TargetSite); msg.AppendFormat(" 异常堆栈信息: {0} \n",ex.StackTrace); msg.AppendFormat(" 异常消息: {0} \n",ex.Message); msg.Append("***************************************"); try { if (File.Exists(FilePath)) { using (StreamWriter tw = File.AppendText(FilePath)) { tw.WriteLine(msg.ToString()); } } else { TextWriter tw = new StreamWriter(FilePath); tw.WriteLine(msg.ToString()); tw.Flush(); tw.Close(); tw = null; } } catch (Exception) { Console.ReadKey(); } }
0 0
- 异常和日志记录
- 保存异常日志记录
- 异常日志记录
- 异常日志记录 DDLog
- 保存异常日志记录类
- 日志记录异常堆栈详细信息
- java记录日志(异常记录)
- java 在文件中记录异常日志
- WCF自定义Attribute记录日志或异常
- spring用aop记录异常日志
- 记录异常日志的7条规则
- 记录异常日志的7条规则
- 记录异常日志的7条规则
- 记录异常日志的7条规则
- 12.4.1 异常与记录日志
- 利用异常类记录调用日志
- 记录异常日志的7条规则
- IO流以日志文件记录异常
- android WebView使用的总结
- linux嵌入式ARM-linux基础题目(比较完整,未看)
- cocos2dx导安卓包常见问题
- Android生成随机验证码技术
- 关于dumpbin和undname的使用
- 异常日志记录
- excel导出csv
- 第11章 程序料理----miniMusic(1)
- SQL中的Collation是个什么鬼?
- Do not be evil-不作恶的谷歌
- UE正常打开文本文件出现乱码解决方法
- 《征服C指针》——读书笔记(3)
- git merge error permission denied
- android实现应用程序只有在第一次启动时显示引导界面 ,以后就不在显示了