WPF简单日志记录

class PLogs
    {
        /// 
        /// 普通日志
        /// 
        /// 类名
        /// 日志记录
        public static void Info(string className, string info)
        {
            WriteLog("INFO", className, info);
        }

        /// 
        /// 警告日志
        /// 
        /// 类名
        /// 日志记录
        public static void Warn(string className, string info)
        {
            WriteLog("WARN", className, info);
        }

        /// 
        /// 错误日志
        /// 
        /// 类名
        /// 日志记录
        public static void Error(string className, string info)
        {
            WriteLog("ERROE", className, info);
        }

        /// 
        /// 写入日志
        /// 
        /// 类名
        /// 日志级别
        /// 日志记录
        private static void WriteLog(string className, string infoLevel, string info)
        {
            string logFilePath = AppDomain.CurrentDomain.BaseDirectory + "/logs";
            if (!Directory.Exists(logFilePath))
            {
                Directory.CreateDirectory(logFilePath);
            }
            string logFileName = logFilePath + "/" + "log_" + DateTime.Now.ToString("yyyyMMdd") + ".log";
            if (!File.Exists(logFileName))
            {
                File.Create(logFileName).Close();
            }
            string logFormat = string.Format("[ {0} ] {1}  {2}  {3}",
                                           DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                           className, infoLevel, info);
            StreamWriter sw = File.AppendText(logFileName);
            sw.WriteLine(logFormat);
            sw.Flush();
            sw.Close();
        }
    }

 

你可能感兴趣的:(unity3d)