码迷,mamicode.com
首页 > Windows程序 > 详细

c# 添加日志

时间:2019-08-08 19:36:18      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:using   sage   ted   private   sys   创建   line   mes   color   

private static void setlog(string message)
        {
            string logPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\log\\";
            if (!Directory.Exists(logPath))//没有则创建
            {
                Directory.CreateDirectory(logPath);
            }
            using (FileStream stream = new FileStream(logPath + DateTime.Now.ToString("yyyyMMddHHmm") + ".txt", FileMode.Append))
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.WriteLine($"{DateTime.Now}:{message}");
            }
        }

 

c# 添加日志

标签:using   sage   ted   private   sys   创建   line   mes   color   

原文地址:https://www.cnblogs.com/Mzg121584668/p/11322940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!