-
Notifications
You must be signed in to change notification settings - Fork 1
/
Logger.cs
44 lines (37 loc) · 1.69 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
using System.Runtime.CompilerServices;
namespace Discord_Bot
{
internal class Logger
{
private static string Timestamp => $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}";
private static async Task _log(object msg, string severity, [CallerMemberName] string caller = "", [CallerLineNumber] int lineNumber = 0)
{
msg = msg.ToString();
if (Program.instance.loggerWebhook == null)
Console.WriteLine($"[{Timestamp}] {caller} line: {lineNumber}: [{severity}]: {msg}");
else
await Program.instance.loggerWebhook.SendMessageAsync($"[{Timestamp}] {caller} line: {lineNumber}: [{severity}]: {msg}");
}
public static Task Log(LogMessage arg)
{
_ = _log(arg.Message, arg.Severity.ToString(), arg.Source);
return Task.CompletedTask;
}
public static async Task logTrace(object msg, [CallerMemberName] string caller = "", [CallerLineNumber] int lineNumber = 0)
{
await _log(msg, "TRACE", caller, lineNumber);
}
public static async Task logError(object msg, [CallerMemberName] string caller = "", [CallerLineNumber] int lineNumber = 0)
{
await _log(msg, "ERROR", caller, lineNumber);
}
public static async Task logInfo(object msg, [CallerMemberName] string caller = "", [CallerLineNumber] int lineNumber = 0)
{
await _log(msg, "INFO", caller, lineNumber);
}
public static async Task logWarn(object msg, [CallerMemberName] string caller = "", [CallerLineNumber] int lineNumber = 0)
{
await _log(msg, "WARN", caller, lineNumber);
}
}
}