c# 添加日志

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

 

posted @ 2019-08-08 18:22  _小马哥  阅读(878)  评论(0编辑  收藏  举报