代码段——写日志文件

        /// <summary>
        /// 写入日志
        /// </summary>
        public void WriteLog(string message)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "/MyLog.txt";
            using (StreamWriter sw = new StreamWriter(path, true, Encoding.Default))
            {
                sw.Flush();
                sw.WriteLine("时间:" + DateTime.Now);
                sw.WriteLine("内容:" + message);
                sw.WriteLine("-------------------------");
            }
        }
posted @ 2023-03-23 16:32  shanzm  阅读(8)  评论(0编辑  收藏  举报
TOP