首页 > 代码库 > C# Common Log function

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 =http://www.mamicode.com/ System.Text.Encoding.Default.GetBytes(info);
        //开始写入
        fs.Write(data, 0, data.Length);
        //清空缓冲区、关闭流、销毁
        fs.Flush();
        fs.Close();
        fs.Dispose();

        return 1;
    }

 

C# Common Log function