-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppLog.cs
More file actions
51 lines (45 loc) · 1.54 KB
/
AppLog.cs
File metadata and controls
51 lines (45 loc) · 1.54 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
using System;
using System.IO;
using System.Text;
namespace PasswordGenLocal
{
internal static class AppLog
{
// Diagnostic log written alongside the executable.
// Filename retained from the predecessor project for continuity with existing deployments.
// Columns: timestamp (ISO 8601 local), type, message, detail
private static readonly string LogPath =
Path.Combine(AppContext.BaseDirectory, "rorg_log.csv");
private static readonly object _lock = new object();
static AppLog()
{
if (!File.Exists(LogPath))
{
try
{
File.WriteAllText(LogPath,
"\"timestamp\",\"type\",\"message\",\"detail\"\r\n",
new UTF8Encoding(false));
}
catch { }
}
}
public static void Write(string eventType, string message, string detail = "")
{
try
{
string line = string.Format(
"\"{0}\",\"{1}\",\"{2}\",\"{3}\"\r\n",
DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"),
Escape(eventType),
Escape(message),
Escape(detail));
lock (_lock)
File.AppendAllText(LogPath, line, new UTF8Encoding(false));
}
catch { }
}
private static string Escape(string? s) =>
(s ?? string.Empty).Replace("\"", "\"\"");
}
}