其他分享
首页 > 其他分享> > 单文件Loger方法

单文件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)
            {
            }
        }

标签:文件,string,GetDirectoryName,Application,Loger,ErrLog,Combine,Path,方法
来源: https://www.cnblogs.com/wml-it/p/16424530.html