forked from DigitalRuby/IPBan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
63 lines (53 loc) · 1.21 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#region Imports
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
#endregion Imports
namespace IPBan
{
public enum LogLevel
{
Info,
Warning,
Error
}
/// <summary>
/// Logger
/// </summary>
public static class Log
{
private static readonly Logger logger;
static Log()
{
try
{
logger = LogManager.GetLogger("FileLogger");
}
catch (Exception ex)
{
Console.WriteLine("Failed to initialize logger: {0}", ex);
}
}
public static void Write(LogLevel level, string text, params object[] args)
{
if (logger == null)
{
return;
}
switch (level)
{
case LogLevel.Info:
logger.Info(text, args);
break;
case LogLevel.Warning:
logger.Warn(text, args);
break;
case LogLevel.Error:
logger.Error(text, args);
break;
}
}
}
}