-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileLogger.cs
More file actions
30 lines (27 loc) · 929 Bytes
/
Copy pathFileLogger.cs
File metadata and controls
30 lines (27 loc) · 929 Bytes
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ScratchBot
{
internal class FileLogger
{
private static readonly string m_logPath = $"{Environment.CurrentDirectory}/_Bot_Log.LOG";
internal static void LogToFile(string _log, bool _append = true)
{
if (!File.Exists(m_logPath))
{
File.Create(m_logPath);
}
List<string> _lines = new List<string>(10);
if (_append)
{
_lines = File.ReadAllLines(m_logPath).ToList();
}
_lines.Add(string.Format("[{0} - {1}]", DateTime.Now.ToString("yyyy-MM-dd--HH-mm"), _log));
File.WriteAllText(m_logPath, _lines.Aggregate("", (current, s) => current + (s + Environment.NewLine)));
}
}
}