Exemple #1
0
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <param name="message"></param>
        public static bool AddMessage(string message)
        {
            try
            {
                //// 记录接收到的微信消息日志
                //// 获取微信消息日志存储位置

                //// 是否记录微信消息日志 1:记录 0:不记录 默认为0
                string isAddWXMessageLog = WebConfigeOpert.GetIsAddWXMessageLog();

                //// 如果不记录日志,那么直接返回
                if (isAddWXMessageLog != "1")
                {
                    return(true);
                }

                //// 微信消息日志记录路径
                string wxMessageLogPath = WebConfigeOpert.GetWXMessageLogPath();

                if (string.IsNullOrEmpty(wxMessageLogPath))
                {
                    return(true);
                }

                DateTime dateNow = System.DateTime.Now;

                //// 检查创建文件夹
                CreateDirectoryByMoth(dateNow, wxMessageLogPath);

                string filePath = string.Format("{0}//{1}//{2}//{3}.txt", wxMessageLogPath, dateNow.ToString("yyyy"), dateNow.ToString("MM"), dateNow.ToString("yyyyMMdd"));
                //// 按照日期创建文件
                CreateFile(filePath);

                //// 写文件
                FileOpert.WriteFile(filePath, message, true);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }