diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 3bbe18c..35b6dc7 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Utilities/Log.cs b/Utilities/Log.cs index 0ee8c94..88a5091 100644 --- a/Utilities/Log.cs +++ b/Utilities/Log.cs @@ -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 Warnings = new(); private static readonly List 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()