From 5502a2d3f6ec945809da9b16b7dccdd3716a820e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 12 Jan 2020 16:03:38 +0200 Subject: Code comments for session logger. --- .../Tango.Logging/SessionFileLogger.cs | 74 +++++++++++++--------- 1 file changed, 43 insertions(+), 31 deletions(-) (limited to 'Software/Visual_Studio/Tango.Logging') diff --git a/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs index f4ce9c2fb..da8079d41 100644 --- a/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs +++ b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs @@ -10,22 +10,24 @@ namespace Tango.Logging { public class SessionFileLogger : ILogger { - #region Properties private bool _inInSession; - private int _writeCount; + private const string FILE_SESSION_EXTENSION = "_session"; + private const int FILE_SIZE_CHECK_COUNT = 100; - public const string FILE_SESSION_EXTENSION = "_session"; - - public static String DefaultLogsFolder { get; private set; } + #region Static Properties - private const int FILE_SIZE_CHECK_COUNT = 100; + public static String DefaultLogsFolder { get; private set; } /// /// Gets or sets the maximum file size limit. /// public static long MaxFileSizeLimit { get; set; } + #endregion + + #region Properties + public bool Enabled { get; set; } public String Folder { get; private set; } @@ -35,6 +37,7 @@ namespace Tango.Logging public String Tag { get; private set; } #endregion + #region Constructors /// /// Initializes the static members of the class. @@ -59,6 +62,9 @@ namespace Tango.Logging } #endregion + + #region Public Methods + /// /// Creates the session. Only one file should be for session log, so removed old file and create a new file. /// @@ -77,6 +83,35 @@ namespace Tango.Logging _inInSession = false; } + /// + /// Called when write to session log file. + /// + /// The output. + public void OnLog(LogItemBase output) + { + if (_inInSession) + { + try + { + if (++_writeCount > FILE_SIZE_CHECK_COUNT && new FileInfo(LogFile).Length > MaxFileSizeLimit) + { + _writeCount = 0; + CreateSession(); + File.AppendAllText(LogFile, "### This log file is a continuation of a previous log file ###" + Environment.NewLine + Environment.NewLine); + } + File.AppendAllText(LogFile, output.ToString() + Environment.NewLine); + } + catch + { + Debug.WriteLine("Error Writing To Session Log File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + } + } + } + + #endregion + + #region Private Methods + /// /// Creates the name of the log file. /// @@ -113,31 +148,8 @@ namespace Tango.Logging { Debug.WriteLine(ex); } - } + } - /// - /// Called when write to session log file. - /// - /// The output. - public void OnLog(LogItemBase output) - { - if (_inInSession) - { - try - { - if(++_writeCount > FILE_SIZE_CHECK_COUNT && new FileInfo(LogFile).Length > MaxFileSizeLimit) - { - _writeCount = 0; - CreateSession(); - File.AppendAllText(LogFile, "### This log file is a continuation of a previous log file ###" + Environment.NewLine + Environment.NewLine); - } - File.AppendAllText(LogFile, output.ToString() + Environment.NewLine); - } - catch - { - Debug.WriteLine("Error Writing To Session Log File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - } - } - } + #endregion } } -- cgit v1.3.1