保存异常日志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();
}
}