-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging.cs
83 lines (70 loc) · 2.16 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
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Serilog;
using Serilog.Core;
using Serilog.Events;
namespace MCFBuilder
{
internal static class Logging
{
public static int? LogLevel { get; set; } = null;
public static void Init()
{
var logLevel = new LoggingLevelSwitch();
if (LogLevel == null)
{
logLevel.MinimumLevel = ((LogEventLevel)1 + (int)LogEventLevel.Fatal);
}
else
{
logLevel.MinimumLevel = (LogEventLevel)LogLevel;
}
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(logLevel)
.WriteTo.Console()
.WriteTo.File($"Logs/debug_.log", rollingInterval: RollingInterval.Hour, restrictedToMinimumLevel: LogEventLevel.Debug)
.WriteTo.File($"Logs/trace_.log", rollingInterval: RollingInterval.Hour, restrictedToMinimumLevel: LogEventLevel.Verbose)
.CreateLogger();
Log.Information("Logger setup successfully");
}
public static void Info(object message)
{
Log.Information(message.ToString());
}
public static void Debug(object message)
{
Log.Debug(message.ToString());
}
public static void Trace(object message)
{
Log.Verbose(message.ToString());
}
public static void Error(ErrorType errorType, object message)
{
Log.Error($"{errorType}: {message}");
}
public static void Error(Exception e)
{
Log.Error(e, e.Message);
}
public static void Fatal(ErrorType errorType, object message)
{
Log.Fatal($"{errorType}: {message}");
System.Environment.Exit(1);
}
public static void Fatal(Exception e)
{
Log.Fatal(e, e.Message);
System.Environment.Exit(1);
}
}
internal enum ErrorType
{
ArgumentException,
CompileException,
RuntimeException
}
}