Created
August 13, 2019 14:23
-
-
Save deepumi/7834dfdefed60301edfde3525f29f91d to your computer and use it in GitHub Desktop.
Logging class for CLI tools!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal sealed class Logger : ILogger | |
{ | |
private readonly FileStream _writer = new FileStream(Config.Configuration["LogFile"], FileMode.Create, FileAccess.Write, | |
FileShare.None, 1024, FileOptions.SequentialScan); | |
private readonly UTF8Encoding _utf = new UTF8Encoding(true); | |
private readonly byte[] _line; | |
internal Logger() => _line = _utf.GetBytes(Environment.NewLine); | |
void ILogger.Log(string message) | |
{ | |
var info = _utf.GetBytes(message + "\n"); | |
_writer.Write(info, 0, info.Length); | |
_writer.Write(_line, 0, _line.Length); | |
} | |
public void Dispose() | |
{ | |
_writer.Flush(); | |
_writer.Dispose(); | |
} | |
} | |
internal interface ILogger : IDisposable | |
{ | |
void Log(string message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment