diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-01-08 13:53:48 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-01-08 13:53:48 +0200 |
| commit | 5a06b997b7ef29c566bad2bc65f927e9443c3888 (patch) | |
| tree | 7c332325fc01f82b68855bf31636830085ba6954 /Software/Visual_Studio/Tango.Logging | |
| parent | 7f05564656644b9af0500657a689c12805aee732 (diff) | |
| download | Tango-5a06b997b7ef29c566bad2bc65f927e9443c3888.tar.gz Tango-5a06b997b7ef29c566bad2bc65f927e9443c3888.zip | |
Implemented maintenance mid-tank graphics.
Implemented session file logger.
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging')
| -rw-r--r-- | Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs | 103 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj | 1 |
2 files changed, 104 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs new file mode 100644 index 000000000..f3c23ca25 --- /dev/null +++ b/Software/Visual_Studio/Tango.Logging/SessionFileLogger.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Logging +{ + public class SessionFileLogger : ILogger + { + private bool _inInSession; + + public const string FILE_SESSION_EXTENSION = "_session"; + + public static String DefaultLogsFolder { get; private set; } + + public bool Enabled { get; set; } + + public String Folder { get; private set; } + + public String LogFile { get; private set; } + + public String Tag { get; private set; } + + static SessionFileLogger() + { + DefaultLogsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Logs", Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName), "session"); + } + + public SessionFileLogger(String folder, String tag) + { + Folder = folder; + Tag = tag; + Directory.CreateDirectory(Folder); + Enabled = true; + } + + public SessionFileLogger() : this(DefaultLogsFolder, Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName)) + { + + } + + public void CreateSession() + { + RemoveOldLogFile(); + LogFile = CreateLogFileName(); + _inInSession = true; + } + + public void EndSession() + { + _inInSession = false; + } + + 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)); + } + + private void RemoveOldLogFile() + { + try + { + if (Directory.Exists(Folder)) + { + string[] fileEntries = Directory.GetFiles(Folder, "*.log"); + foreach (string fileName in fileEntries) + { + try + { + File.Delete(fileName); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + } + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + + public void OnLog(LogItemBase output) + { + if (_inInSession) + { + try + { + File.AppendAllText(LogFile, output.ToString() + Environment.NewLine); + } + catch + { + Debug.WriteLine("Error Writing To Session Log File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + } + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj index 311579625..e2e2b1edd 100644 --- a/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj +++ b/Software/Visual_Studio/Tango.Logging/Tango.Logging.csproj @@ -69,6 +69,7 @@ <Compile Include="LogFile.cs" /> <Compile Include="ProducerConsumerQueue.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="SessionFileLogger.cs" /> <Compile Include="SimpleStringLogger.cs" /> <Compile Include="VSOutputLogger.cs" /> </ItemGroup> |
