예제 #1
0
파일: LoggerUtil.cs 프로젝트: sobne/Nkit
        public static void Append(string message, string name = "", string module = "", LoggerLevel logType = LoggerLevel.Debug, bool logTypeDist = false)
        {
            if (string.IsNullOrEmpty(_rootPath))
            {
                _rootPath = AppDomain.CurrentDomain.BaseDirectory + "Log";
                FileHelper.CreateFloder(_rootPath);
            }
            var path = _rootPath + "/" + DateTime.Now.ToString("yyyy-MM-dd");

            FileHelper.CreateFloder(path);

            DelLog();

            var fileName = logTypeDist ? GetName(name, logType.ToString()) : GetName(name);
            var logFile  = Path.Combine(path, fileName);

            var content = GetLogWithTime(module, message, logType.ToString());

            Console.WriteLine(content);
            FileHelper.Append(logFile, content);
        }
예제 #2
0
파일: LoggerUtil.cs 프로젝트: sobne/Nkit
 private static void ClearFolder()
 {
     try
     {
         _lastClearTime = DateTime.Now;
         var dtLine = DateTime.Today.AddMonths(-6);
         var ov     = LoggerConfigManager.Instance.OverTime.Value;
         var o      = LoggerConfigManager.Instance.OverTime.TimeSpan.ToLower();
         if (o.Equals("day"))
         {
             dtLine = DateTime.Today.AddDays(-ov);
         }
         else if (o.Equals("month"))
         {
             dtLine = DateTime.Today.AddMonths(-ov);
         }
         else if (o.Equals("year"))
         {
             dtLine = DateTime.Today.AddYears(-ov);
         }
         var folder = new DirectoryInfo(_rootPath);
         foreach (var dir in folder.GetDirectories())
         {
             var dtDir = DateTime.ParseExact(dir.Name, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
             if (dtLine > dtDir)
             {
                 dir.Delete(true);
             }
         }
         FileHelper.Append(Path.Combine(_rootPath, "clear.log"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "  C");
     }
     catch (Exception)
     {
         //throw;
     }
 }