首页 > 开发 > 综合 > 正文

添加日志文件

2024-07-21 02:26:13
字体:
来源:转载
供稿:网友

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表