|
|
@@ -119,7 +119,7 @@ namespace Dongke.IBOSS.PRD.Basics.Library
|
|
|
if (!File.Exists(logFile))
|
|
|
{
|
|
|
// 旧文件删除
|
|
|
- //DeleteLogFile(logFilePath);
|
|
|
+ DeleteLogFile(logFilePath);
|
|
|
}
|
|
|
|
|
|
// 把错误消息写入日志文件
|
|
|
@@ -173,35 +173,55 @@ namespace Dongke.IBOSS.PRD.Basics.Library
|
|
|
try
|
|
|
{
|
|
|
// 日志文件夹里面的所有的日志文件的取得
|
|
|
- DirectoryInfo diDirectoryInfo = new DirectoryInfo(logFilePath);
|
|
|
- FileInfo[] fiFileInfo = diDirectoryInfo.GetFiles();
|
|
|
+ //DirectoryInfo diDirectoryInfo = new DirectoryInfo(logFilePath);
|
|
|
+ //FileInfo[] fiFileInfo = diDirectoryInfo.GetFiles();
|
|
|
|
|
|
- // 旧文件删除
|
|
|
- string strLogFile = string.Empty;
|
|
|
- foreach (FileInfo fileInfo in fiFileInfo)
|
|
|
- {
|
|
|
- strLogFile = fileInfo.Name.Remove(fileInfo.Name.LastIndexOf('.'));
|
|
|
+ //// 旧文件删除
|
|
|
+ //string strLogFile = string.Empty;
|
|
|
+ //foreach (FileInfo fileInfo in fiFileInfo)
|
|
|
+ //{
|
|
|
+ // strLogFile = fileInfo.Name.Remove(fileInfo.Name.LastIndexOf('.'));
|
|
|
|
|
|
- DateTime? datDateTime;
|
|
|
- bool bolCheckValid = Utility.IsValidDate(strLogFile, out datDateTime);
|
|
|
- if (!bolCheckValid)
|
|
|
- {
|
|
|
- // 无效的文件删除
|
|
|
- File.Delete(fileInfo.FullName);
|
|
|
- }
|
|
|
- else
|
|
|
+ // DateTime? datDateTime;
|
|
|
+ // bool bolCheckValid = Utility.IsValidDate(strLogFile, out datDateTime);
|
|
|
+ // if (!bolCheckValid)
|
|
|
+ // {
|
|
|
+ // // 无效的文件删除
|
|
|
+ // File.Delete(fileInfo.FullName);
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // // 旧文件的删除
|
|
|
+ // if (datDateTime < DateTime.Now.AddDays(DELETE_FILE_PERIOD))
|
|
|
+ // {
|
|
|
+ // File.Delete(fileInfo.FullName);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ string[] files = System.IO.Directory.GetFiles(logFilePath, "*.log");
|
|
|
+ if (files != null && files.Length > 0)
|
|
|
+ {
|
|
|
+ DateTime deathDate = DateTime.Now.Date.AddDays(-60);
|
|
|
+ foreach (string file in files)
|
|
|
{
|
|
|
- // 旧文件的删除
|
|
|
- if (datDateTime < DateTime.Now.AddDays(DELETE_FILE_PERIOD))
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //if (File.GetCreationTime(file) < deathDate)
|
|
|
+ if (File.GetLastWriteTime(file) < deathDate)
|
|
|
+ {
|
|
|
+ File.Delete(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
{
|
|
|
- File.Delete(fileInfo.FullName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- throw ex;
|
|
|
+ //throw ex;
|
|
|
}
|
|
|
}
|
|
|
|