保存异常日志txt

 

try

{

//执行的代码

}

catch (Exception em)
{
new ExcInsertFile().SetInsertFile(em.ToString());
}

 

//保存异常日志txt

public void SetInsertFile(String str)
{
FileStream myFs = null;
StreamWriter mySw = null;
try
{
myFs = new FileStream("Log/WSExceptionTing.txt", FileMode.Create);
mySw = new StreamWriter(myFs);
mySw.WriteLine(DateTime.Now.ToString() + ": " + str);
}
catch (Exception exmc)
{
return;
}
finally
{
if (mySw != null)
mySw.Close();
if (myFs != null)
myFs.Close();
}
}

posted @ 2019-05-29 18:09  近在远方的风景  阅读(204)  评论(0编辑  收藏  举报