-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.cs
36 lines (29 loc) · 1.02 KB
/
Log.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
using System;
using System.IO;
namespace CommonsLibrary.Logging
{
public class Log
{
private readonly string _filePath;
private static Log? _logger;
private Log(string filePath) => _filePath = filePath;
public static Log GetLogger(string filePath) => _logger ??= new Log(filePath);
private void WriteLog(LogLevel level, string message, Exception? exception = null)
{
using StreamWriter writer = new StreamWriter(_filePath, true);
writer.WriteLine($"{DateTime.Now} {level} {exception} {message}");
}
public void Info(string message) =>
WriteLog(LogLevel.Info, message);
public void Warning(string message) =>
WriteLog(LogLevel.Warning, message);
public void Error(string message, Exception exception) =>
WriteLog(LogLevel.Error, message, exception);
private enum LogLevel
{
Info,
Warning,
Error,
}
}
}