-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogs.cs
31 lines (27 loc) · 950 Bytes
/
Logs.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
using System.IO;
using System;
using System.Reflection;
namespace CommonsLibrary.Logging
{
public class Logs
{
private readonly DateTime _dt;
private readonly string _logType;
private readonly string _error;
private readonly string _logMessage;
public Logs(string logType, string error, string message)
{
_dt = DateTime.Now;
_logType = logType;
_error = error;
_logMessage = message;
}
public void WriteToFile(string path)
{
path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\" + path;
if (string.IsNullOrEmpty(path) || !File.Exists(path)) throw new ArgumentNullException(path, "Path is null, empty or incorrect");
using StreamWriter writer = new(path, true);
writer.WriteLine($"[{_logType} {_dt}] {_error}: {_logMessage}");
}
}
}