.Net异常发布器的开发(2) (转)[@more@]
下面以一个类便是对发布器进行
配置操作,如获取上述三个
文件的位置并设置相关配置: /// /// ExceptionSetting 的摘要说明。 /// public class ExceptionSetting { /// /// 获取用于异常处理的文件夹 /// public static string FilePath { get { string fullpath; if (AppConfig.GetAppSetting("ExceptionPath") != null) { fullpath = AppConfig.GetAppSetting("ExceptionPath"); while (fullpath.StartsWith("")) { fullpath = fullpath.Remove(0,1); } } else { fullpath = Path.GetDirectoryName(Path.GetFullPath("Temp.
XML")); } fullpath = Path.GetFullPath(fullpath); fullpath = fullpath + ""; if (!Directory.Exists(Path.GetDirectoryName(fullpath))) { Directory.CreateDirectory(Path.GetDirectoryName(fullpath)); } return fullpath; } } /// /// 获取或设置用于异常处理的文件夹的字符串 /// public static string FilePathSettingString { get { return AppConfig.GetAppSetting("ExceptionPath"); } set { AppConfig.SaveAppSetting("ExceptionPath",value); } } /// /// 获取或设置
系统异常记录类型,默认为使用XML文件记录 /// public static CanUseExceptionLogType ExceptionLogType { get { string exceptionLogType = AppConfig.GetAppSetting("ExceptionLogType"); if (exceptionLogType.ToLower().Trim() == CanUseExceptionLogType.SystemLog.ToString().ToLower()) { return CanUseExceptionLogType.SystemLog; } else if (exceptionLogType.ToLower().Trim() == CanUseExceptionLogType.All.ToString().ToLower()) { return CanUseExceptionLogType.All; } else return CanUseExceptionLogType.XMLFile; } set { AppConfig.SaveAppSetting("ExceptionLogType",value.ToString()); } }
}
而下面这一个类则是用于对异常发布器用到的三个文件进行读写的: /// /// LogAccess 的摘要说明。 /// public class LogAccess { /// /// 写入异常处理日志 /// /// public static void WriteLogFile(ExceptionLogData ds) { ds.WriteXml(ExceptionSetting.FilePath +"ExceptionLog.XML"); } /// /// 读出异常处理日志 /// /// public static ExceptionLogData ReadLogFile() { ExceptionLogData ds = new ExceptionLogData(); if ( !File.Exists(ExceptionSetting.FilePath +"ExceptionLog.XML")) { ds.WriteXml(ExceptionSetting.FilePath +"ExceptionLog.XML"); } ds.Clear(); ds.ReadXml(ExceptionSetting.FilePath +"ExceptionLog.XML"); return ds; } /// /// 读出自定义通用信息 /// /// public static CustomOutMessageData GetCustomOutMessage() { CustomOutMessageData ds = new CustomOutMessageData(); if ( !File.Exists(ExceptionSetting.FilePath +"CustomOutMessage.XML")) { ds.WriteXml(ExceptionSetting.FilePath +"CustomOutMessage.XML"); } ds.Clear(); ds.ReadXml(ExceptionSetting.FilePath +"CustomOutMessage.XML"); return ds; } /// /// 写入自定义通用信息 /// /// public static void SaveCustomOutMessage(CustomOutMessageData ds) { ds.WriteXml(ExceptionSetting.FilePath +"CustomOutMessage.XML"); } /// /// 获取异常处理定义信息 /// /// 读取到的异常处理定义信息 public static ExceptionDetailData GetExceptionDetail() { ExceptionDetailData exceptionDetailDS = new ExceptionDetailData(); if ( !File.Exists(ExceptionSetting.FilePath +"ExceptionList.xml")) { exceptionDetailDS.WriteXml(ExceptionSetting.FilePath +"ExceptionList.xml"); FileStream fs = new FileStream(ExceptionSetting.FilePath +"ExceptionList.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter w = new StreamWriter(fs); w.BaseStream.Seek(0, SeekOrigin.End); w.Write("nn<!--nType:异常的类型,系统依据此值和下面的InMessage一起判定异常的处理方式,此值与异常类型的完全限定名严格相等,不区分大小写;nInMessage:异常信息中的关键字,系统依据此关键字和上面的异常类型一起判定异常的处理方式,关键字最多可以有四个,不区分大小写,有层次关系;nHelpLink:自定义的有关异常的帮助文件路径;nOutMessage:自定义的向
用户显示的友好信息。n-->"); w.Flush(); w.Close(); } exceptionDetailDS.Clear(); exceptionDetailDS.ReadXml(ExceptionSetting.FilePath +"ExceptionList.xml"); return exceptionDetailDS; } /// /// 保存异常处理定义信息 /// /// 要保存的异常处理定义信息 public static void SaveExceptionDetail(ExceptionDetailData exceptionDetailDS) { exceptionDetailDS.WriteXml(ExceptionSetting.FilePath +"ExceptionList.xml"); FileStream fs = new FileStream(ExceptionSetting.FilePath +"ExceptionList.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter w = new StreamWriter(fs); w.BaseStream.Seek(0, SeekOrigin.End); w.Write("nn<!--nType:异常的类型,系统依据此值和下面的InMessage一起判定异常的处理方式,此值与异常类型的完全限定名严格相等,不区分大小写;nInMessage:异常信息中的关键字,系统依据此关键字和上面的异常类型一起判定异常的处理方式,关键字最多可以有四个,不区分大小写,有层次关系;nHelpLink:自定义的有关异常的帮助文件路径;nOutMessage:自定义的向用户显示的友好信息。n-->"); w.Flush(); w.Close(); }
}
<%}%>
(未完待续)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10794571/viewspace-974809/,如需转载,请注明出处,否则将追究法律责任。
请登录后发表评论
登录
全部评论
<%=items[i].createtime%>
<%=items[i].content%>
<%if(items[i].items.items.length) { %>
<%for(var j=0;j
<%}%> <%if(items[i].items.total > 5) { %>
<%}%>
<%=items[i].items.items[j].createtime%>
<%=items[i].items.items[j].username%> 回复 <%=items[i].items.items[j].tousername%>: <%=items[i].items.items[j].content%>
还有<%=items[i].items.total-5%>条评论
) data-count=1 data-flag=true>点击查看
<%}%>
转载于:http://blog.itpub.net/10794571/viewspace-974809/
本文介绍了一个.NET异常发布器的配置方法,包括获取异常处理文件夹路径、设置异常记录类型及读写异常日志等关键配置。

2818






