Skip to content

Commit ee5bd2d

Browse files
committed
* Added ability to disable logging
* Fixed being able to export logs even when there are no logs
1 parent 09b1eb0 commit ee5bd2d

File tree

17 files changed

+66
-15
lines changed

17 files changed

+66
-15
lines changed

MemPlus/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
<setting name="InvokeGarbageCollector" serializeAs="String">
145145
<value>True</value>
146146
</setting>
147+
<setting name="LoggingEnabled" serializeAs="String">
148+
<value>True</value>
149+
</setting>
147150
</MemPlus.Properties.Settings>
148151
</userSettings>
149152
</configuration>

MemPlus/Business/LOG/LogController.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ internal sealed class LogController : IDisposable
1717
{
1818
#region Variables
1919
/// <summary>
20+
/// True if logging is enabled, otherwise false
21+
/// </summary>
22+
private bool _loggingEnabled;
23+
/// <summary>
2024
/// The list of available Log objects
2125
/// </summary>
2226
private readonly List<Log> _logList;
@@ -96,6 +100,7 @@ internal sealed class LogController : IDisposable
96100
/// </summary>
97101
internal LogController()
98102
{
103+
_loggingEnabled = true;
99104
_logList = new List<Log>();
100105

101106
_autoClearTimer = new Timer();
@@ -111,18 +116,20 @@ internal LogController()
111116
/// <summary>
112117
/// Initialize a new LogController object
113118
/// </summary>
119+
/// <param name="enabled">True if logging is enabled, otherwise false</param>
114120
/// <param name="autoClear">True if the logs should be cleared automatically</param>
115121
/// <param name="clearInterval">The interval for when ApplicationLog objects should automatically be cleared</param>
116122
/// <param name="saveToFile">True if logs should be written to a file</param>
117123
/// <param name="saveDirectory">The directory to which the logs should be written</param>
118-
internal LogController(bool autoClear, int clearInterval, bool saveToFile, string saveDirectory)
124+
internal LogController(bool enabled, bool autoClear, int clearInterval, bool saveToFile, string saveDirectory)
119125
{
126+
_loggingEnabled = enabled;
120127
_logList = new List<Log>();
121128

122129
_autoClearTimer = new Timer();
123130
_autoClearTimer.Elapsed += OnTimedEvent;
124131
_autoClearTimer.Interval = clearInterval;
125-
_autoClearTimer.Enabled = autoClear;
132+
SetAutoClear(autoClear);
126133

127134
_startTime = DateTime.Now;
128135
// Set this after the DateTime has been established
@@ -135,13 +142,20 @@ internal LogController(bool autoClear, int clearInterval, bool saveToFile, strin
135142
SetSaveToFile(saveToFile);
136143
}
137144

145+
internal void SetLoggingEnabled(bool enabled)
146+
{
147+
_loggingEnabled = enabled;
148+
}
149+
138150
/// <summary>
139151
/// Set whether logs should be cleared automatically or not
140152
/// </summary>
141153
/// <param name="autoClear">True if logs should be cleared automatically, otherwise false</param>
142154
internal void SetAutoClear(bool autoClear)
143155
{
144-
_autoClearTimer.Enabled = autoClear;
156+
bool timerEnabled = autoClear;
157+
if (!_loggingEnabled) timerEnabled = false;
158+
_autoClearTimer.Enabled = timerEnabled;
145159
}
146160

147161
/// <summary>
@@ -159,7 +173,13 @@ internal void SetAutoClearInterval(int clearInterval)
159173
/// <param name="saveToFile">True if logs should be saved to a file, otherwise false</param>
160174
internal void SetSaveToFile(bool saveToFile)
161175
{
162-
if (_saveToFile == saveToFile) return;
176+
if (!_loggingEnabled && (_saveToFile || saveToFile))
177+
{
178+
DisposeFileResources();
179+
_saveToFile = saveToFile;
180+
return;
181+
}
182+
163183
if (_saveToFile && !saveToFile)
164184
{
165185
// Make sure the contents of the log file is written before disabling this function
@@ -215,6 +235,8 @@ private void OnTimedEvent(object sender, ElapsedEventArgs e)
215235
/// <param name="l">The Log object that needs to be added</param>
216236
internal void AddLog(Log l)
217237
{
238+
if (!_loggingEnabled) return;
239+
218240
_logList.Add(l);
219241
LogAddedEvent?.Invoke(l);
220242
if (_saveToFile) WriteLogToFile(l);
@@ -311,6 +333,7 @@ internal List<Log> GetLogs(LogType? logType)
311333
/// <param name="exportType">The type of export that should be performed</param>
312334
internal void Export(string path, LogType? logType, ExportType exportType)
313335
{
336+
if (_logList.Count == 0) return;
314337
List<Log> exportList;
315338

316339
if (logType != null)

MemPlus/Business/UTILS/Utils.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,11 @@ internal static bool ExportRamSticks(LogController logController)
154154
/// <returns>True if the operation completed successfully, otherwise false</returns>
155155
internal static bool ExportLogs(LogType? logType, LogController logController)
156156
{
157-
if (logType != null)
158-
{
159-
if (logController.GetLogs(logType).Count == 0) return false;
160-
}
157+
if (logController.GetLogs(logType).Count == 0) return false;
161158

162159
SaveFileDialog sfd = new SaveFileDialog
163160
{
164-
Filter = "Text file (*.txt)|*.txt|HTML file (*.html)|*.html|CSV file (*.csv)|*.csv|Excel file (*.csv)|*.csv"
161+
Filter = "Log file (*.log)|*.log|Text file (*.txt)|*.txt|HTML file (*.html)|*.html|CSV file (*.csv)|*.csv|Excel file (*.csv)|*.csv"
165162
};
166163

167164
if (sfd.ShowDialog() != true) return false;

MemPlus/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MemPlus/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,8 @@
138138
<Setting Name="InvokeGarbageCollector" Type="System.Boolean" Scope="User">
139139
<Value Profile="(Default)">True</Value>
140140
</Setting>
141+
<Setting Name="LoggingEnabled" Type="System.Boolean" Scope="User">
142+
<Value Profile="(Default)">True</Value>
143+
</Setting>
141144
</Settings>
142145
</SettingsFile>

MemPlus/Resources/Languages/ar_SA.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128

129129
<!-- Automatic translation - Needs translation -->
130130
<system:String x:Key="LogSettings">تسجيل</system:String>
131+
<system:String x:Key="LoggingEnabled">تم تمكين التسجيل</system:String>
131132
<system:String x:Key="AutoClearLogs">مسح السجلات تلقائيا من الذاكرة كل</system:String>
132133
<system:String x:Key="LogFile">حفظ سجلات تلقائيا إلى ملف</system:String>
133134
<system:String x:Key="LogFilePath">مسار ملف السجل:</system:String>

MemPlus/Resources/Languages/de_DE.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
<system:String x:Key="InvokeGarbageCollector">.NET-Garbage-Collector aufrufen</system:String>
129129

130130
<system:String x:Key="LogSettings">Protokollierung</system:String>
131+
<system:String x:Key="LoggingEnabled">Protokollierung aktiviert</system:String>
131132
<system:String x:Key="AutoClearLogs">Protokolle automatisch aus dem Speicher löschen jede</system:String>
132133
<system:String x:Key="LogFile">Protokolle automatisch in Datei speichern</system:String>
133134
<system:String x:Key="LogFilePath">Protokolldateipfad:</system:String>

MemPlus/Resources/Languages/en_US.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@
127127
<system:String x:Key="AutoOptimizeWarning">This option will only work if the RAM Monitor is enabled!</system:String>
128128
<system:String x:Key="InvokeGarbageCollector">Invoke .NET garbage collector</system:String>
129129

130-
<!-- Automatic translation - Needs translation -->
131130
<system:String x:Key="LogSettings">Logging</system:String>
131+
<system:String x:Key="LoggingEnabled">Logging enabled</system:String>
132132
<system:String x:Key="AutoClearLogs">Automatically clear logs from memory every</system:String>
133133
<system:String x:Key="LogFile">Automatically save logs to file</system:String>
134134
<system:String x:Key="LogFilePath">Log file path:</system:String>

MemPlus/Resources/Languages/es_ES.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129

130130
<!-- Automatic translation - Needs translation -->
131131
<system:String x:Key="LogSettings">El registro</system:String>
132+
<system:String x:Key="LoggingEnabled">Registro habilitado</system:String>
132133
<system:String x:Key="AutoClearLogs">Borrar automáticamente los registros de la memoria cada</system:String>
133134
<system:String x:Key="LogFile">Guardar automáticamente los registros en el archivo</system:String>
134135
<system:String x:Key="LogFilePath">Ruta del archivo de registro:</system:String>

MemPlus/Resources/Languages/fr_FR.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130

131131
<!-- Automatic translation - Needs translation -->
132132
<system:String x:Key="LogSettings">Enregistrement</system:String>
133+
<system:String x:Key="LoggingEnabled">Enregistrement activé</system:String>
133134
<system:String x:Key="AutoClearLogs">Effacer automatiquement les journaux de la mémoire tous les</system:String>
134135
<system:String x:Key="LogFile">Enregistrer automatiquement les journaux dans un fichier</system:String>
135136
<system:String x:Key="LogFilePath">Chemin du fichier journal:</system:String>

0 commit comments

Comments
 (0)