using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.Logging
{
///
/// Represents an file logger.
///
///
public class FileLogger : ILogger
{
///
/// Gets or sets the log file.
///
public String LogFile { get; private set; }
///
/// Initializes a new instance of the class.
///
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)));
}
///
/// Initializes a new instance of the class.
///
/// The log file.
public FileLogger(String logFile)
: this()
{
Directory.CreateDirectory(Path.GetDirectoryName(logFile));
LogFile = logFile;
}
///
/// Called when a new library trace is available.
///
/// The output.
public void OnLog(LogItemBase output)
{
File.AppendAllText(LogFile, output.ToString() + Environment.NewLine);
}
private bool _isEnabled;
///
/// Gets or sets a value indicating whether this is enabled.
///
public bool Enabled
{
get
{
return _isEnabled;
}
set
{
_isEnabled = value;
}
}
///
/// Gets or sets a value indicating whether this will be notified about logs without waiting for the logs queue.
///
public bool Immediate { get; set; }
}
}