| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- namespace HPSocketCS.Extended
 
- {
 
-    public class SystemFileLogs
 
-     {
 
-        public SystemFileLogs() { 
 
-        
 
-        }
 
-      static string logsPath =HPSocketCS.Extended.CommonLibrary.GetFullDirectoryPath(HPSocketCS.Extended.CommonLibrary.BasePath) + "Logs\\"+DateTime.Now.ToString("yyyy-MM-dd")+".log";
 
-         /// <summary>
 
-        /// 分割日志文件
 
-        /// </summary>
 
-        /// <param name="fileName"></param>
 
-        public static void SplitLogFile(string fileName)
 
-        {
 
-            try
 
-            {
 
-                if (System.IO.File.Exists(fileName))
 
-                {
 
-                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
 
-                    if ((fileInfo.Length / 1024 / 1024) >= 5)
 
-                    {
 
-                        string newFileFullName = System.IO.Path.GetDirectoryName(fileName) + "\\" + System.IO.Path.GetFileNameWithoutExtension(fileName) + "(" + DateTime.Now.ToString("HH:mm:ss") + ").log";
 
-                        System.IO.File.Copy(fileName, newFileFullName);
 
-                        string msg = "【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】日志文件过大,已被分割保存,可以当前日志目录找到...\r\n";
 
-                        System.IO.File.WriteAllText(fileName, msg, Encoding.UTF8);
 
-                    }
 
-                }
 
-            }
 
-            catch { }
 
-        }
 
-        /// <summary>
 
-        /// 写日志
 
-        /// </summary>
 
-        /// <param name="txt">日志内容</param>
 
-        public static void WriteLogs(string txt)
 
-        {
 
-            SystemFileLogs.WriteLogs(txt, logsPath);
 
-        }
 
-        /// <summary>
 
-        /// 写日志
 
-        /// </summary>
 
-        /// <param name="txt">日志内容</param>
 
-        public static void WriteLogs(string txt, HPSocketCS.Extended.CustomTraceListener _TraceListenerLog)
 
-        {
 
-            if (_TraceListenerLog != null)
 
-            {
 
-                _TraceListenerLog.WriteLine( "【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】"+txt);
 
-            }
 
-            SystemFileLogs.WriteLogs(txt, logsPath);
 
-        }
 
-        /// <summary>
 
-        /// 写日志
 
-        /// </summary>
 
-        /// <param name="txt">日志内容</param>
 
-        /// <param name="fullPath">日志文件全路径</param>
 
-        static void WriteLogs(string txt, string fullPath)
 
-        {
 
-            try
 
-            {
 
-                if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(fullPath)))
 
-                {
 
-                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fullPath));
 
-                }
 
-                SplitLogFile(fullPath);
 
-                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fullPath, true, Encoding.UTF8))
 
-                {
 
-                    sw.WriteLine("【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】" + txt);
 
-                    sw.Flush();
 
-                    sw.Close();
 
-                }
 
-            }
 
-            catch { }
 
-        }
 
-     }
 
- }
 
 
  |