Esempio n. 1
0
        /// <summary>
        /// 插入纯净的日志行
        /// </summary>
        /// <param name="text"></param>
        public static void WritePure(string text)
        {
            string dirPath  = PathHandle.GetFilePath(logPath.TrimEnd('/') + "/");
            string filePath = dirPath + "log_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".log";

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            using (StreamWriter sw = new StreamWriter(filePath, true, Encoding.Default))
            {
                sw.WriteLine(text);
                sw.Flush();
                sw.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 写入条日志,包含http上下文
        /// </summary>
        /// <param name="ext">文件夹名</param>
        /// <param name="text"></param>
        public static void Write(string ext, string text)
        {
            string requestUrl = System.Web.HttpContext.Current.Request.RawUrl;
            string dirPath    = PathHandle.GetFilePath(logPath.TrimEnd('/') + "/");
            string filePath   = dirPath + ext + "log_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".log";

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            text = " ######################### " + DateTime.Now.ToString() + "(" + requestUrl + ") #########################\r\n" + " " + text + "\r\n\r\n";
            using (StreamWriter sw = new StreamWriter(filePath, true, Encoding.Default))
            {
                sw.WriteLine(text);
                sw.Flush();
                sw.Close();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 写入条纯文本日志
        /// </summary>
        /// <param name="text"></param>
        public static void WritePur(string text)
        {
            string dirPath = PathHandle.GetFilePath(logPath.TrimEnd('/') + "/");

            WritePur(text, dirPath);
        }