如何将错误消息输出到绝对路径下

编写前需要加入引用空间  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);

}

猜你喜欢

转载自www.cnblogs.com/970728-qi/p/9826476.html