向服务器写入错误日志-log

        /// <summary>
        /// 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
        /// </summary>
        /// <param name="sWord">要写入日志里的文本内容</param>
        public static void LogResult(string sWord)
        {
            string strPath = HttpContext.Current.Server.MapPath("log");
            strPath = strPath + "\" + DateTime.Now.ToString().Replace(":", "") + ".txt";
            StreamWriter fs = new StreamWriter(strPath, false, System.Text.Encoding.Default);
            fs.Write(sWord);
            fs.Close();
        }

其中:Log文件夹要存在服务器的根目录下。

原文地址:https://www.cnblogs.com/KTblog/p/4730302.html