zoukankan      html  css  js  c++  java
  • .net 文件接口的封装,写日志,创建文件log

        public class FileSupport
        {
            public static FileSupport Instance = new FileSupport();
            public static string mRoot =Environment.CurrentDirectory+"/log";
    
            public string mPath = Environment.CurrentDirectory + "/log/" + System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
    
            public bool FileExit()
            {
                if (!Directory.Exists(mRoot))//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(mRoot);
                }
                if (!File.Exists(mPath))
                {
                   return false;
                }
                return true;
            }
    
            public void Write(string msg)
            {
                FileStream fs;
                if(!FileExit())
                {
                   fs=   File.Create(mPath);//创建该文件
                }
                else
                {
                    fs = new FileStream(mPath, FileMode.Append);
                }
    
                StreamWriter sw = new StreamWriter(fs);
                //开始写入
                var addstr = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "    "+msg + "
    ";
                sw.Write(addstr);
                //清空缓冲区
                sw.Flush();
                //关闭流
                sw.Close();
                fs.Close();
            }
    
        }
  • 相关阅读:
    mysqllog
    清理:db上面的过期的binlog,释放磁盘空间。 (转)
    linux下shell命令trap
    mvc
    uci随笔
    luci 随笔
    shell脚本 整数比较
    lua学习
    OPENWRT make menuconfig错误之一
    openwrt 中make的使用
  • 原文地址:https://www.cnblogs.com/leolzi/p/7985792.html
Copyright © 2011-2022 走看看