mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 15:55:39 +02:00
Added settings option for log rotation
This commit is contained in:
@@ -78,7 +78,8 @@ internal class Globals
|
||||
public static string VersionDatabase = ""; // Version - Database
|
||||
public static string VersionPerun = "DEBUG"; // Version - Perun
|
||||
|
||||
public static string LastLogLocation = ""; // Last used log location
|
||||
public static string LastLogLocation = ""; // Last used log location
|
||||
public static bool RotateLogs = false; // Rotate logs true/false
|
||||
|
||||
public static CurrentMissionClass CurrentMission = new CurrentMissionClass(); // Actual mission information single ton
|
||||
|
||||
|
||||
@@ -59,14 +59,17 @@ class LogController
|
||||
}
|
||||
|
||||
// Delete old files - log rotation
|
||||
DirectoryInfo di = new DirectoryInfo(LogFileDir);
|
||||
FileInfo[] files = di.GetFiles("*.log");
|
||||
|
||||
foreach (FileInfo fi in files)
|
||||
if (Globals.RotateLogs)
|
||||
{
|
||||
if (fi.LastAccessTime < DateTime.Now.AddDays(-7))
|
||||
DirectoryInfo di = new DirectoryInfo(LogFileDir);
|
||||
FileInfo[] files = di.GetFiles("*.log");
|
||||
|
||||
foreach (FileInfo fi in files)
|
||||
{
|
||||
fi.Delete();
|
||||
if (fi.LastAccessTime < DateTime.Now.AddDays(-7))
|
||||
{
|
||||
fi.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@
|
||||
this.label20 = new System.Windows.Forms.Label();
|
||||
this.tim_HW_status = new System.Windows.Forms.Timer(this.components);
|
||||
this.con_Button_See_log = new System.Windows.Forms.Button();
|
||||
this.con_check_delete_logs = new System.Windows.Forms.CheckBox();
|
||||
this.con_GroupBox_1.SuspendLayout();
|
||||
this.con_GroupBox_2.SuspendLayout();
|
||||
this.con_GroupBox_3.SuspendLayout();
|
||||
@@ -621,6 +622,7 @@
|
||||
//
|
||||
// con_GroupBox_5
|
||||
//
|
||||
this.con_GroupBox_5.Controls.Add(this.con_check_delete_logs);
|
||||
this.con_GroupBox_5.Controls.Add(this.con_check_minimize_to_tray);
|
||||
this.con_GroupBox_5.Location = new System.Drawing.Point(13, 370);
|
||||
this.con_GroupBox_5.Name = "con_GroupBox_5";
|
||||
@@ -816,6 +818,20 @@
|
||||
this.con_Button_See_log.UseVisualStyleBackColor = true;
|
||||
this.con_Button_See_log.Click += new System.EventHandler(this.con_Button_See_log_Click);
|
||||
//
|
||||
// con_check_delete_logs
|
||||
//
|
||||
this.con_check_delete_logs.AutoSize = true;
|
||||
this.con_check_delete_logs.Checked = true;
|
||||
this.con_check_delete_logs.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.con_check_delete_logs.Location = new System.Drawing.Point(105, 19);
|
||||
this.con_check_delete_logs.Name = "con_check_delete_logs";
|
||||
this.con_check_delete_logs.Size = new System.Drawing.Size(138, 17);
|
||||
this.con_check_delete_logs.TabIndex = 25;
|
||||
this.con_check_delete_logs.Text = "Rotate logs after 7 days";
|
||||
this.con_check_delete_logs.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
|
||||
this.con_check_delete_logs.UseVisualStyleBackColor = true;
|
||||
this.con_check_delete_logs.Validated += new System.EventHandler(this.con_check_delete_logs_Validated);
|
||||
//
|
||||
// form_Main
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@@ -945,6 +961,7 @@
|
||||
private System.Windows.Forms.Label label20;
|
||||
private System.Windows.Forms.Timer tim_HW_status;
|
||||
private System.Windows.Forms.Button con_Button_See_log;
|
||||
private System.Windows.Forms.CheckBox con_check_delete_logs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace Perun_v1
|
||||
con_txt_dcs_instance.Text = Properties.Settings.Default.DCS_Instance.ToString();
|
||||
con_com_loglevel.SelectedIndex = Properties.Settings.Default.OTHER_Log_Level;
|
||||
con_check_minimize_to_tray.Checked = Properties.Settings.Default.OTHER_Minimize_to_Tray;
|
||||
con_check_delete_logs.Checked = Properties.Settings.Default.OTHER_Log_Rotate;
|
||||
}
|
||||
|
||||
private void form_Main_SaveSettings()
|
||||
@@ -147,6 +148,7 @@ namespace Perun_v1
|
||||
Properties.Settings.Default.DCS_Instance = Int32.Parse(con_txt_dcs_instance.Text);
|
||||
Properties.Settings.Default.OTHER_Log_Level = con_com_loglevel.SelectedIndex;
|
||||
Properties.Settings.Default.OTHER_Minimize_to_Tray = con_check_minimize_to_tray.Checked;
|
||||
Properties.Settings.Default.OTHER_Log_Rotate = con_check_delete_logs.Checked;
|
||||
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
@@ -355,6 +357,12 @@ namespace Perun_v1
|
||||
Properties.Settings.Default.OTHER_Minimize_to_Tray = con_check_minimize_to_tray.Checked;
|
||||
}
|
||||
|
||||
private void con_check_delete_logs_Validated(object sender, EventArgs e)
|
||||
{
|
||||
// Changed rotate logs state
|
||||
Properties.Settings.Default.OTHER_Log_Rotate = con_check_delete_logs.Checked;
|
||||
}
|
||||
|
||||
private void con_Button_Reset_Flags_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Reset error flags
|
||||
@@ -572,6 +580,10 @@ namespace Perun_v1
|
||||
Globals.StatusHistoryConnection = Globals.StatusConnection;
|
||||
Globals.ErrorsHistoryGame = Globals.ErrorsGame;
|
||||
}
|
||||
|
||||
// Check if we shall rate logs
|
||||
Globals.RotateLogs = con_check_minimize_to_tray.Checked;
|
||||
|
||||
// Update status icons at main form - SRS
|
||||
if ((ExtSRSStatus != Globals.StatusSRS) || Globals.AppForceIconReload)
|
||||
{
|
||||
@@ -776,5 +788,7 @@ namespace Perun_v1
|
||||
Process.Start(Globals.LastLogLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,5 +178,17 @@ namespace Perun_v1.Properties {
|
||||
this["OTHER_Minimize_to_Tray"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
public bool OTHER_Log_Rotate {
|
||||
get {
|
||||
return ((bool)(this["OTHER_Log_Rotate"]));
|
||||
}
|
||||
set {
|
||||
this["OTHER_Log_Rotate"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,5 +41,8 @@
|
||||
<Setting Name="OTHER_Minimize_to_Tray" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="OTHER_Log_Rotate" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -46,6 +46,9 @@
|
||||
<setting name="OTHER_Minimize_to_Tray" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="OTHER_Log_Rotate" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
</Perun_v1.Properties.Settings>
|
||||
</userSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||
|
||||
Reference in New Issue
Block a user