using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PunchingMistake { public class LogHelper { private static string CodeVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Trim(); // //保存日志的文件夹 // private static string logPath = AppDomain.CurrentDomain.BaseDirectory + @"log\"; /// /// 写日志 /// /// /// public static void WriteLog(string msg, string errorFile = "") { try { if (string.IsNullOrEmpty(msg)) { return; } else { msg = string.Format("程序版本号:{0},Time:{1},Message:{2}", CodeVersion, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"), msg); } //如果不存在log文件夹 则创建 if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } StreamWriter sw = File.AppendText(logPath + errorFile + DateTime.Now.ToString("yyyyMMdd") + ".Log"); sw.WriteLine(msg); sw.Close(); } catch (Exception ex) { } } } }