aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Logging/FileLogger.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-11-16 13:38:56 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-11-16 13:38:56 +0200
commit914f4db513477d9aff726546bac47545195a3e37 (patch)
treed2ff190fd84b1dfaa03eec76563c431592ece7ff /Software/Visual_Studio/Tango.Logging/FileLogger.cs
parent65d01ff549d80fbe13ff5e966df216c9f7c03653 (diff)
downloadTango-914f4db513477d9aff726546bac47545195a3e37.tar.gz
Tango-914f4db513477d9aff726546bac47545195a3e37.zip
Rename "Visual Studio" to "Visual_Studio"
Rename "External Repositories" to "External_Repositories".
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging/FileLogger.cs')
-rw-r--r--Software/Visual_Studio/Tango.Logging/FileLogger.cs83
1 files changed, 83 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Logging/FileLogger.cs b/Software/Visual_Studio/Tango.Logging/FileLogger.cs
new file mode 100644
index 000000000..ca17aa367
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Logging/FileLogger.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Logging
+{
+ /// <summary>
+ /// Represents an <see cref="ILogger"/> file logger.
+ /// </summary>
+ /// <seealso cref="Tango.Logging.ILogger" />
+ public class FileLogger : ILogger
+ {
+
+ /// <summary>
+ /// Gets or sets the log file.
+ /// </summary>
+ public String LogFile { get; private set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FileLogger"/> class.
+ /// </summary>
+ public FileLogger()
+ {
+ _isEnabled = true;
+ String logsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "logs");
+ Directory.CreateDirectory(logsFolder);
+ LogFile = Path.Combine(logsFolder, string.Format("{1}-{0:yyyy-MM-dd_hh-mm-ss}.log", DateTime.Now, Path.GetFileNameWithoutExtension(System.AppDomain.CurrentDomain.FriendlyName)));
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FileLogger"/> class.
+ /// </summary>
+ /// <param name="logFile">The log file.</param>
+ public FileLogger(String logFile)
+ : this()
+ {
+ Directory.CreateDirectory(Path.GetDirectoryName(logFile));
+ LogFile = logFile;
+ }
+
+ /// <summary>
+ /// Called when a new library trace is available.
+ /// </summary>
+ /// <param name="output">The output.</param>
+ public void OnTrace(LogItemBase output)
+ {
+ OnError(output);
+ }
+
+ /// <summary>
+ /// Called when a new library exception is available.
+ /// </summary>
+ /// <param name="output">The output.</param>
+ public void OnError(LogItemBase output)
+ {
+ File.AppendAllText(LogFile, output.ToString() + Environment.NewLine);
+ }
+
+ private bool _isEnabled;
+ /// <summary>
+ /// Gets or sets a value indicating whether this <see cref="ILogger" /> is enabled.
+ /// </summary>
+ public bool Enabled
+ {
+ get
+ {
+ return _isEnabled;
+ }
+ set
+ {
+ _isEnabled = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this <see cref="ILogger" /> will be notified about logs without waiting for the logs queue.
+ /// </summary>
+ public bool Immediate { get; set; }
+ }
+}