using System;
using System.Text;
using System.IO;
namespace SomeNamespace
{
sealed class SimpleLogger : IDisposable
{
///
/// Singleton instance
///
private static readonly SimpleLogger _instance = new Logger();
private readonly string _logFilePath;
private readonly FileStream _logFileStream;
public static SimpleLogger Instance
{
get { return _instance; }
}
private SimpleLogger()
{
_logFilePath = Program.ApplicationFolder + @"\bithub.log";
_logFileStream = new FileStream(_logFilePath, FileMode.Append);
}
public void Dispose()
{
if (_logFileStream != null)
{
_logFileStream.Flush();
_logFileStream.Close();
}
}
///
/// Creates logfile entry in the following form: 01.01.1970 00:00 -:- MESSAGE
///
public void WriteLine(string message)
{
message = DateTime.Now.ToString("g") + " -:- " + message + Environment.NewLine;
Byte[] output = new UTF8Encoding(true).GetBytes(message);
_logFileStream.Write(output, 0, output.Length);
_logFileStream.Flush();
}
}
}