-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logging.cs
70 lines (64 loc) · 1.2 KB
/
Logging.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace authenticator.Logging
{
public class Logger
{
private string path;
private LoggingLevels level;
public enum LoggingLevels: ushort
{
DEBUG = 0,
INFO = 1,
WARN = 2,
ERROR = 3
}
public Logger(string log_path = "auth.log", string log_level = "INFO")
{
path = log_path;
if(Enum.TryParse<LoggingLevels>(log_level, out level) == false)
level = LoggingLevels.INFO;
}
public void debug(string message)
{
if(level >= LoggingLevels.DEBUG){
log("DEBUG\t" + message);
}
}
public void info(string message)
{
if (level >= LoggingLevels.INFO)
{
log("INFO\t" + message);
}
}
public void warn(string message)
{
if (level >= LoggingLevels.WARN)
{
log("WARN\t" + message);
}
}
public void error(string message)
{
if (level >= LoggingLevels.ERROR)
{
log("ERROR\t" + message);
}
}
public void log(string message)
{
write(DateTime.Now.ToString()+"\t"+message);
}
private void write(string message)
{
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(message);
}
}
}
}