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();
        }

  

原文地址:https://www.cnblogs.com/lampon/p/3864863.html