Browse Source

修复清理日志时路径有问题的bug

yuzhengyang 7 years ago
parent
commit
b90d395b49

BIN
Fork.Net/.vs/Fork.Net/v15/Server/sqlite3/storage.ide


BIN
Fork.Net/.vs/Fork.Net/v15/sqlite3/storage.ide


+ 1 - 58
Fork.Net/Azylee.Utils/Azylee.Core/LogUtils/SimpleLogUtils/Log.cs

@@ -49,13 +49,9 @@ namespace Azylee.Core.LogUtils.SimpleLogUtils
         const int CACHE_DAYS = 30;//缓存天数
 
         private object LogFileLock = new object();//写日志文件锁
-
         private bool IsWriteFile = false;//是否写日志文件
-        public string LogPath = AppDomain.CurrentDomain.BaseDirectory + LOG_PATH;
+        private string LogPath = AppDomain.CurrentDomain.BaseDirectory + LOG_PATH;
         public LogLevel LogLevel = LogLevel.All;//日志输出等级
-
-        bool IsStart = false;
-        ConcurrentQueue<LogModel> Queue = new ConcurrentQueue<LogModel>();
         #endregion
 
         public Log()
@@ -68,37 +64,6 @@ namespace Azylee.Core.LogUtils.SimpleLogUtils
                 LogLevel = level;
             }
         }
-        void Start()
-        {
-            return;
-            if (!IsStart)
-            {
-                IsStart = true;
-                Task.Factory.StartNew(() =>
-                {
-                    while (IsStart)
-                    {
-                        Thread.Sleep(500);
-
-                        if (Queue.Any())
-                        {
-                            List<LogModel> list = new List<LogModel>();
-                            for (int i = 0; i < Queue.Count; i++)
-                            {
-                                LogModel model = null;
-                                if (Queue.TryDequeue(out model)) list.Add(model);
-                            }
-                            if (ListTool.HasElements(list)) WriteFile(list);
-                        }
-                    }
-                });
-            }
-        }
-        void Stop()
-        {
-            if (IsStart)
-                IsStart = false;
-        }
         public bool SetWriteFile(string logPath, bool isWrite = true)
         {
             if (isWrite && !string.IsNullOrWhiteSpace(logPath))
@@ -180,28 +145,6 @@ namespace Azylee.Core.LogUtils.SimpleLogUtils
                 }
             }
         }
-        private void WriteFile(List<LogModel> list)
-        {
-            if (IsWriteFile)
-            {
-                lock (LogFileLock)
-                {
-                    //设置日志目录
-                    string logPath = AppDomain.CurrentDomain.BaseDirectory + LogPath;
-                    string file = string.Format(@"{0}\{1}.txt", logPath, DateTime.Now.ToString("yyyy-MM-dd"));
-                    //创建日志目录
-                    DirTool.Create(logPath);
-                    //整理要输出的内容
-                    List<string> txts = new List<string>();
-                    foreach (var item in list)
-                    {
-                        txts.Add(string.Format(LOG_FORMAT, item.CreateTime.ToString(TIME_FORMAT), item.Type.ToString(), item.Message));
-                    }
-                    //写出日志
-                    TxtTool.Append(file, txts);
-                }
-            }
-        }
         /// <summary>
         /// 根据分类分配目录
         /// </summary>

+ 6 - 8
Fork.Net/Azylee.Utils/Azylee.Core/LogUtils/StatusLogUtils/StatusLog.cs

@@ -43,10 +43,10 @@ namespace Azylee.Core.LogUtils.StatusLogUtils
         #endregion
 
         #region 基础属性
-        const string LOG_PATH = "log";//存储路径
+        const string LOG_PATH = @"log\status";//存储路径
         const int CACHE_DAYS = 30;//缓存天数
 
-        public string LogPath = AppDomain.CurrentDomain.BaseDirectory + LOG_PATH;//存储路径
+        private string LogPath = AppDomain.CurrentDomain.BaseDirectory + LOG_PATH;//存储路径
 
         DateTime Time = DateTime.Now;//标记当前时间
         int Interval = 60 * 1000;//监测间隔时间
@@ -138,12 +138,10 @@ namespace Azylee.Core.LogUtils.StatusLogUtils
                     AppCpuPer = (int)AppProcessor.NextValue(),
                     AppRamUsed = AppInfoTool.RAM(),
                 };
-
-                //设置日志目录和日志文件
-                string filePath = DirTool.Combine(LogPath, "status");
-                string file = DirTool.Combine(filePath, DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
                 //创建日志目录
-                DirTool.Create(filePath);
+                DirTool.Create(LogPath);
+                //设置日志目录和日志文件
+                string file = DirTool.Combine(LogPath, DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
                 //写出日志
                 TxtTool.Append(file, status.ToString());
 
@@ -156,7 +154,7 @@ namespace Azylee.Core.LogUtils.StatusLogUtils
         /// </summary>
         private void Cleaner()
         {
-            List<string> files = FileTool.GetFile(AppDomain.CurrentDomain.BaseDirectory + LogPath);
+            List<string> files = FileTool.GetFile(LogPath);
             if (ListTool.HasElements(files))
             {
                 files.ForEach(f =>