-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
45 lines (40 loc) · 1.34 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
using FreeSpaceChecker.Interfaces;
using System;
using System.IO;
namespace FreeSpaceChecker
{
class Logger : ILogger
{
private string loggerPath;
public Logger(string loggerPath)
{
this.loggerPath = loggerPath;
}
public void Log(string msg, bool isEndLine = false)
{
if (!Directory.Exists(Path.GetDirectoryName(loggerPath)))
Directory.CreateDirectory(Path.GetDirectoryName(loggerPath));
try
{
string logLine = System.String.Format("{0:G}: {1}", System.DateTime.Now.ToString().PadRight(20), msg);
Console.WriteLine(logLine);
using (System.IO.StreamWriter sw = System.IO.File.AppendText(loggerPath))
{
if(isEndLine)
{
sw.WriteLine("====================================================================================================================>");
}
else
{
if (!string.IsNullOrWhiteSpace(msg))
sw.WriteLine(logLine);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}