mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-16 02:13:39 +12:00
[Feature] Clear logfile, keep only 2 mb (#312), version 1.2.3.7
This commit is contained in:
parent
86c0771c3e
commit
2c4e9c656c
|
@ -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")]
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue