Added settings option for log rotation

This commit is contained in:
Szymon Porwolik
2021-02-17 23:40:23 +01:00
parent 0050f5fab5
commit f7a9301015
7 changed files with 60 additions and 7 deletions

View File

@@ -79,6 +79,7 @@ internal class Globals
public static string VersionPerun = "DEBUG"; // Version - Perun
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

View File

@@ -59,6 +59,8 @@ class LogController
}
// Delete old files - log rotation
if (Globals.RotateLogs)
{
DirectoryInfo di = new DirectoryInfo(LogFileDir);
FileInfo[] files = di.GetFiles("*.log");
@@ -70,4 +72,5 @@ class LogController
}
}
}
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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>

View File

@@ -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>