-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cs
More file actions
72 lines (59 loc) · 1.79 KB
/
Logger.cs
File metadata and controls
72 lines (59 loc) · 1.79 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ESRecorder
{
static class Logger
{
private static StreamWriter? file = null;
private static Mutex mut = new Mutex();
public static void Initialise()
{
string temp = Path.GetTempPath();
string f = Path.Combine(temp, "esrecord.log");
string f0 = Path.Combine(temp, "esrecord.0.log");
if (File.Exists(f))
{
if (File.Exists(f0))
File.Delete(f0);
File.Move(f, f0);
}
file = new(File.Open(f, FileMode.Create));
file.AutoFlush = true;
}
public static void WriteRaw(string message)
{
mut.WaitOne();
if (file == null)
{
Initialise();
file.WriteLine("Initialise() was not called. This file was created automatically");
}
file.Write(message);
mut.ReleaseMutex();
}
public static void WriteLog(string source, string message)
{
mut.WaitOne();
if (file == null)
{
Initialise();
file.WriteLine("Initialise() was not called. This file was created automatically");
}
file.WriteLine(DateTime.Now.ToLocalTime().ToString("s") + " :: " + source + " -> " + message);
mut.ReleaseMutex();
}
public static void Close()
{
mut.WaitOne();
if (file == null) return;
file.Flush();
file.Close();
mut.ReleaseMutex();
}
}
}