@@ -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 )
0 commit comments