aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Logging
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2020-01-12 15:57:41 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2020-01-12 15:57:41 +0200
commiteb56ae78a58d07f5e11c2c034a67be96256a4c87 (patch)
tree0009bba7a19390453642c9d7b1648bf8f16c62e4 /Software/Visual_Studio/Tango.Logging
parent9949e351e152a929da696ef2f0a1f8b1668e83fa (diff)
parentd8b3bbece9ee09b68b6707c276ce4101f91e2943 (diff)
downloadTango-eb56ae78a58d07f5e11c2c034a67be96256a4c87.tar.gz
Tango-eb56ae78a58d07f5e11c2c034a67be96256a4c87.zip
MERGE
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging')
-rw-r--r--Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs46
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