-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeferringLogger.cs
34 lines (28 loc) · 918 Bytes
/
DeferringLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.IO;
namespace BanditMilitias
{
// simplified from https://github.com/BattletechModders/IRBTModUtils
internal class DeferringLogger
{
private readonly LogWriter logWriter;
internal DeferringLogger()
{
logWriter = new LogWriter(new StreamWriter(SubModule.logFilename, true));
}
internal LogWriter? Debug => Globals.Settings.Debug ? logWriter : null;
internal readonly struct LogWriter
{
private readonly StreamWriter sw;
public LogWriter(StreamWriter sw)
{
this.sw = sw;
sw.AutoFlush = true;
}
internal void Log(object input)
{
sw.WriteLine($"[{DateTime.Now.ToLongTimeString()}] {(string.IsNullOrEmpty(input?.ToString()) ? "IsNullOrEmpty" : input)}");
}
}
}
}