mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 17:05:39 +02:00
Added log rotation (7 days)
This commit is contained in:
@@ -26,8 +26,8 @@ class LogController
|
||||
DirectoryInfo LogDirectoryInfo = null;
|
||||
FileInfo LogFileInfo;
|
||||
|
||||
string LogFilePath = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "\\Perun\\";
|
||||
LogFilePath = LogFilePath + "Perun_Log_" + Globals.AppInstanceID + "_" + System.DateTime.Today.ToString("yyyyddMM") + "." + "txt";
|
||||
string LogFileDir = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "\\Perun\\";
|
||||
string LogFilePath = LogFileDir + "Perun_Log_" + Globals.AppInstanceID + "_" + System.DateTime.Today.ToString("yyyyMMdd") + "." + "log";
|
||||
LogFileInfo = new FileInfo(LogFilePath);
|
||||
LogDirectoryInfo = new DirectoryInfo(LogFileInfo.DirectoryName);
|
||||
if (!LogDirectoryInfo.Exists) LogDirectoryInfo.Create();
|
||||
@@ -57,6 +57,16 @@ class LogController
|
||||
// Do nothing - TBD error handling
|
||||
}
|
||||
|
||||
// TBD: log rotation
|
||||
// Delete old files - log rotation
|
||||
DirectoryInfo di = new DirectoryInfo(LogFileDir);
|
||||
FileInfo[] files = di.GetFiles("*.log");
|
||||
|
||||
foreach (FileInfo fi in files)
|
||||
{
|
||||
if (fi.LastAccessTime < DateTime.Now.AddDays(-7))
|
||||
{
|
||||
fi.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user