public static void writelog(string log) { streamwriter fw = null; //string filepath = directory.getcurrentdirectory(); string filepath = appdomain.currentdomain.basedirectory; if (!filepath.endswith(@"\resource")) { filepath = filepath + "resource"; } string filename = filepath + "\\log.txt"; try { if (file.exists(filename)) { fw = file.appendtext(filename); } else { fw = file.createtext(filename); } fw.writeline(log); } catch (exception e) { } finally { if (fw != null) { try { fw.close(); } catch (exception e1) { } } } }
//resource 文件夹下有个log.txt文件,用于记录错误日志
在其他方法中调用:
writelog("时间:" + datetime.now.tostring());
writelog("xxx 方法错误");
writelog("error:" + e.tostring().trim());
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论