C#保存日志

        public void SetLog(string content)
        {
            string hh = Server.MapPath("/log/") + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            if (!File.Exists(hh))
            {
                string dir = Path.GetDirectoryName(hh);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            FileStream fs = new FileStream(hh, FileMode.Append, FileAccess.Write, FileShare.Read);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(content);
            sw.Close();
            fs.Close();
        }

  

posted @ 2014-07-24 09:53  lampon  阅读(1005)  评论(0编辑  收藏  举报