[Feature] Clear logfile, keep only 2 mb (#312), version 1.2.3.7

This commit is contained in:
Markus Hofknecht 2022-02-05 11:28:19 +01:00
parent 86c0771c3e
commit 2c4e9c656c
2 changed files with 29 additions and 5 deletions

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.3.6")]
[assembly: AssemblyFileVersion("1.2.3.6")]
[assembly: AssemblyVersion("1.2.3.7")]
[assembly: AssemblyFileVersion("1.2.3.7")]

View file

@ -16,13 +16,31 @@ namespace SystemTrayMenu.Utilities
internal static class Log
{
private const string LogfileLastExtension = "_last";
private static readonly Logger LogValue = new(string.Empty);
private static readonly List<string> Warnings = new();
private static readonly List<string> Infos = new();
internal static void Initialize()
{
Logger.Start(new FileInfo(GetLogFilePath()));
string fileNamePath = GetLogFilePath();
FileInfo fileInfo = new FileInfo(fileNamePath);
if (fileInfo.Length > 2000000)
{
string fileNamePathLast = GetLogFilePath(LogfileLastExtension);
try
{
File.Delete(fileNamePathLast);
File.Move(fileNamePath, fileNamePathLast);
}
catch (Exception ex)
{
Log.Warn($"Can not clear logfile:'{fileNamePathLast}'", ex);
}
}
Logger.Start(fileInfo);
}
internal static void Info(string message)
@ -50,18 +68,24 @@ namespace SystemTrayMenu.Utilities
$"{ex}");
}
internal static string GetLogFilePath()
internal static string GetLogFilePath(string backup = "")
{
return Path.Combine(
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
$"SystemTrayMenu"),
$"log-{Environment.MachineName}.txt");
$"log-{Environment.MachineName}{backup}.txt");
}
internal static void OpenLogFile()
{
ProcessStart(GetLogFilePath());
string lastLogfile = GetLogFilePath(LogfileLastExtension);
if (File.Exists(lastLogfile))
{
ProcessStart(lastLogfile);
}
}
internal static void WriteApplicationRuns()