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

 

转载于:https://www.cnblogs.com/Mzg121584668/p/11322940.html

你可能感兴趣的:(c# 添加日志)