-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
43 lines (31 loc) · 948 Bytes
/
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
using System;
using System.IO;
using System.Text;
public class Logger {
public Logger(string fn) {
FileName = fn;
}
string FileName { get; }
string CurrentDateTime {
get {
var dt = DateTime.Now;
return $"{dt.Year}/{dt.Month}/{dt.Day} {dt.Hour}:{dt.Minute}";
}
}
public void WriteLine(string text) {
try {
using var sw = new StreamWriter(FileName, true, Encoding.UTF8);
sw.WriteLine($"[{CurrentDateTime}]: {text}");
} catch (Exception) {
}
}
public void WriteLine (Exception ex) {
WriteLine($"{ex.GetType()}: {ex.Message}");
WriteLine($"Stack Trace: {ex.StackTrace}.");
}
}
public static class StaticLogger {
public static Logger Logger;
public static void WriteLine (string text) => Logger.WriteLine(text);
public static void WriteLine(Exception ex) => Logger.WriteLine(ex);
}