项目中很多地方需要保存当前信息,或者打印文件流特将此方法保存
/// <summary> /// 添加本地日志 /// </summary> /// <param name="path"></param> /// <param name="content"></param> public static void WriteLog( string content) { try { string path = Application.StartupPath + "\\logs\\"; ; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = path + @"\log.txt"; if (!File.Exists(path)) { File.Create(path); } content = content + "\r\n"; File.AppendAllText(path, content); } catch(Exception ex) { } }