/// <summary> /// 写入记事本 /// </summary> /// <param name="log">日志内容</param> /// <param name="filepath">文件路径(含文件名)</param> /// <returns></returns> private static bool WriteTxt(string log, string filepath) { try { string folder = filepath.Substring(0, filepath.LastIndexOf(‘\\‘)); // 创建目录 if (Directory.Exists(folder) == false) { Directory.CreateDirectory(folder); } // 当文件不存在时创建文件 if (File.Exists(filepath) == false) { FileStream fs = File.Create(filepath); fs.Close(); } // 写入文件内容 File.AppendAllText(filepath, "【" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "】" + log + "\r\n", Encoding.Default); return true; } catch { return false; } }