diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-01-12 15:56:17 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-01-12 15:56:17 +0200 |
| commit | d8b3bbece9ee09b68b6707c276ce4101f91e2943 (patch) | |
| tree | d76ba12b6e61c41277142f7c7604f4b6aaa9ae86 /Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs | |
| parent | 9016d57f876a70952dda4419d68b568b586ef0ec (diff) | |
| download | Tango-d8b3bbece9ee09b68b6707c276ce4101f91e2943.tar.gz Tango-d8b3bbece9ee09b68b6707c276ce4101f91e2943.zip | |
Add session log to TFS PPC and Machine Studio.
Related Work Items: #2306
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs index f3c23ca25..f4ce9c2fb 100644 --- a/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs +++ b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs @@ -10,12 +10,22 @@ namespace Tango.Logging { public class SessionFileLogger : ILogger { + #region Properties private bool _inInSession; - public const string FILE_SESSION_EXTENSION = "_session"; + private int _writeCount; + public const string FILE_SESSION_EXTENSION = "_session"; + public static String DefaultLogsFolder { get; private set; } + private const int FILE_SIZE_CHECK_COUNT = 100; + + /// <summary> + /// Gets or sets the maximum file size limit. + /// </summary> + public static long MaxFileSizeLimit { get; set; } + public bool Enabled { get; set; } public String Folder { get; private set; } @@ -24,9 +34,15 @@ namespace Tango.Logging public String Tag { get; private set; } + #endregion + #region Constructors + /// <summary> + /// Initializes the static members of the class. + /// </summary> static SessionFileLogger() { - DefaultLogsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Logs", Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName), "session"); + DefaultLogsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Logs", Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName), "Session"); + MaxFileSizeLimit = 1000000 * 10; //10 MB } public SessionFileLogger(String folder, String tag) @@ -35,13 +51,17 @@ namespace Tango.Logging Tag = tag; Directory.CreateDirectory(Folder); Enabled = true; + _writeCount = 0; } public SessionFileLogger() : this(DefaultLogsFolder, Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName)) { } - + #endregion + /// <summary> + /// Creates the session. Only one file should be for session log, so removed old file and create a new file. + /// </summary> public void CreateSession() { RemoveOldLogFile(); @@ -49,16 +69,26 @@ namespace Tango.Logging _inInSession = true; } + /// <summary> + /// Ends the session. Set flag _inInSession to false. + /// </summary> public void EndSession() { _inInSession = false; } + /// <summary> + /// Creates the name of the log file. + /// </summary> + /// <returns></returns> private String CreateLogFileName() { return Path.Combine(Folder, string.Format("{1}-{0:dd-MM-yyyy_HH-mm-ss}{2}.log", DateTime.Now, Tag, FILE_SESSION_EXTENSION)); } + /// <summary> + /// Delete the old log file if is existed. + /// </summary> private void RemoveOldLogFile() { try @@ -85,12 +115,22 @@ namespace Tango.Logging } } + /// <summary> + /// Called when write to session log file. + /// </summary> + /// <param name="output">The output.</param> 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 |
