单文件Loger方法

 public static void Log(string category, string log)
        {
            try
            {
                if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog")))
                {
                    Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog"));
                }

                string path = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
                File.AppendAllText(path, string.Format("[{0}][{1}] {2} {3}", DateTime.Now.ToString("H:mm:ss"), category, log, Environment.NewLine));
            }
            catch (Exception)
            {
            }
        }
posted @ 2022-06-29 18:18  码农阿亮  阅读(52)  评论(0编辑  收藏  举报