private void writelog(string getdata, string logmessage) {
string strpath = null;
filestream fs = null;
streamwriter m_streamwriter = null;
string logfolder = path.getdirectoryname(application.executablepath) + @"/log";
if(!directory.exists(logfolder)) {
directory.createdirectory(logfolder);
}
string logfilename = system.datetime.now.tostring("yyyymmdd");
strpath = logfolder + "//"+logfilename + ".txt";
fs = new filestream(strpath, filemode.openorcreate, fileaccess.write);
m_streamwriter = new streamwriter(fs);
m_streamwriter.basestream.seek(0, seekorigin.end);
m_streamwriter.writeline("--------{0} {1}----begin-----", datetime.now.tolongdatestring(), datetime.now.tolongtimestring());
m_streamwriter.writeline("接收到的数据:/r/n"+getdata);
m_streamwriter.writeline("操作结果:"+logmessage);
m_streamwriter.writeline("----end-----");
m_streamwriter.flush();
m_streamwriter.close();
fs.close();
}添加日志文件
商业源码热门下载www.html.org.cn
新闻热点
疑难解答