
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CallCenter.Utility.log
{
    public class LogInterface
    {
        //心连心接口调用 日志
        public static void WriteLog(string strLog)
        {
            //string sFilePath = System.Web.HttpContext.Current.Server.MapPath("\\Log\\" + DateTime.Now.ToString("yyyyMM"));
            string sFilePath = "D:\\CallCenter_log\\LogInterface\\" + DateTime.Now.ToString("yyyy-MM");
            string sFileName = "" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
            sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径
            if (!Directory.Exists(sFilePath))//验证路径是否存在
            {
                Directory.CreateDirectory(sFilePath);
                //不存在则创建
            }
            FileStream fs;
            StreamWriter sw;
            if (File.Exists(sFileName))
            //验证文件是否存在，有则追加，无则创建
            {
                fs = new FileStream(sFileName, FileMode.Append, FileAccess.Write);
            }
            else
            {
                fs = new FileStream(sFileName, FileMode.Create, FileAccess.Write);
            }
            sw = new StreamWriter(fs);
            sw.WriteLine("记录时间：[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "] -- " + RequestString.GetIP() + "  " + strLog + "\r\n");
            sw.Close();
            fs.Close();
        }
    }
}