编写前需要加入引用空间 using system,io
新建一个方法 private static void printerror(string log)
{
filestream file=new filestream("存入的文件名+后缀",filemode.append);//把错误消息追加到文件里
streamwriter sw-=new streamwriter(file);//实例化文件写入流
console.writerline("date.now.tostring()"+" "+log); //log是传入的
sw.close();//关闭写入流
file.close();//关闭文件流
}
这个方法要在 异常处理块中调用
try
{
.........
}
catch(exception e)
{
pirnterror(e.message); //调用printerror()方法
throw new exception("调用-----出错"+e,message);
}