-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogs.cs
More file actions
43 lines (38 loc) · 1.29 KB
/
Logs.cs
File metadata and controls
43 lines (38 loc) · 1.29 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
using System.Threading;
namespace CleanCache
{
internal class Logs
{
private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private static string localdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Replace("Roaming", "LocalLow");
public static async Task Register(string log)
{
string localpath = Path.Combine(localdata, "Clean Cash");
Directory.CreateDirectory(localpath);
string logspath = Path.Combine(localpath, "Logs");
Directory.CreateDirectory(logspath);
var actualdate = DateTime.Now;
string logfile = Path.Combine(logspath, $"log-{actualdate:dd-MM-yyyy}.txt");
await _semaphore.WaitAsync();
try
{
using (var wr = File.AppendText(logfile))
{
await wr.WriteLineAsync($"[{actualdate.ToShortTimeString()}] {log}");
await wr.FlushAsync();
}
}
finally
{
_semaphore.Release();
}
}
}
}