mirror of
https://github.com/Ellpeck/ExtremelySimpleLogger.git
synced 2024-05-05 11:27:06 +02:00
30 lines
697 B
C#
30 lines
697 B
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace ExtremelySimpleLogger {
|
|
public class FileSink : Sink {
|
|
|
|
private readonly StreamWriter writer;
|
|
|
|
public FileSink(string file, bool append) :
|
|
this(new FileInfo(file), append) {
|
|
}
|
|
|
|
public FileSink(FileInfo file, bool append) {
|
|
var dir = file.Directory;
|
|
if (dir != null && !dir.Exists)
|
|
dir.Create();
|
|
|
|
if (!append && file.Exists)
|
|
file.Delete();
|
|
|
|
this.writer = file.AppendText();
|
|
this.writer.AutoFlush = true;
|
|
}
|
|
|
|
public override void Log(string s) {
|
|
this.writer.WriteLine(s);
|
|
}
|
|
|
|
}
|
|
} |