C#创建文件夹,往里追字符串。

时间:2021-12-29 21:08:39
  /// <summary>写文本日志</summary>
        /// <param name="StrMessage">日志消息</param>
        /// <param name="LogPath">默认指定文件路径</param>
        /// <param name="LogName">日志文本名(不含后缀/默认为当日时间)</param>
        /// <returns>写入成功</returns>

        static public bool WriteFile(String StrMessage, String LogPath = null, String LogName = null)
        {
            if (!string.IsNullOrEmpty(LogPath)) LogFilePath = LogPath;
            LogFileName = (LogName ?? DateTime.Now.ToString("yyyyMMdd")) + @".txt";
            var FullPath = LogFilePath + LogFileName;
            try
            {
                if (!Directory.Exists(LogFilePath)) Directory.CreateDirectory(LogFilePath);
                File.AppendAllText(FullPath, StrMessage, Encoding.UTF8);
            }
            catch (Exception ex)
            {
                //LogHelper.WriteLogEx(typeof(TextFileMethod), ex);
                return false;
            }
            return true;
        }

  这他妈的 失忆了,啥都不会了、标记一下。