C# Common Log function

    public int Log(string info)
    {
        info = "-----------------------------" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-----------------------------\n" + info;

        FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("/log/") + DateTime.Now.ToString("yyyyMMdd") + "log.txt", FileMode.Append);
        //获得字节数组
        byte[] data = System.Text.Encoding.Default.GetBytes(info);
        //开始写入
        fs.Write(data, 0, data.Length);
        //清空缓冲区、关闭流、销毁
        fs.Flush();
        fs.Close();
        fs.Dispose();

        return 1;
    }

 

posted @ 2017-03-30 15:39 araki 阅读(...) 评论(...) 编辑 收藏