forked from ajkroeg/ShellShuffler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
47 lines (39 loc) · 1.42 KB
/
Logger.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
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.IO;
namespace ShellShuffler
{
class Logger
{
private static StreamWriter logStreamWriter;
private bool enableLogging = false;
public Logger(string modDir, string fileName, bool enableLogging)
{
string filePath = Path.Combine(modDir, $"{fileName}.log");
if (File.Exists(filePath))
{
File.Delete(filePath);
}
logStreamWriter = File.AppendText(filePath);
logStreamWriter.AutoFlush = true;
this.enableLogging = enableLogging;
}
public void LogMessage(string message)
{
if (enableLogging)
{
string ts = DateTime.UtcNow.ToString("HH:mm:ss.ffff", System.Globalization.CultureInfo.InvariantCulture);
logStreamWriter.WriteLine($"INFO: {ts} - {message}");
}
}
public void LogError(string message)
{
string ts = DateTime.UtcNow.ToString("HH:mm:ss.ffff", System.Globalization.CultureInfo.InvariantCulture);
logStreamWriter.WriteLine($"ERROR: {ts} - {message}");
}
public void LogException(Exception exception)
{
string ts = DateTime.UtcNow.ToString("HH:mm:ss.ffff", System.Globalization.CultureInfo.InvariantCulture);
logStreamWriter.WriteLine($"CRITICAL: {ts} - {exception}");
}
}
}