-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugNdjsonSessionLog.cs
More file actions
40 lines (35 loc) · 1.13 KB
/
DebugNdjsonSessionLog.cs
File metadata and controls
40 lines (35 loc) · 1.13 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
using System.Text.Json;
using System.Text.Json.Nodes;
namespace WorkshopUploader;
/// <summary>Session 9fc458: NDJSON to %TEMP%\debug-9fc458.log (writable from Program Files). Remove after root cause confirmed.</summary>
internal static class DebugNdjsonSessionLog
{
private const string SessionId = "9fc458";
internal static string LogPath => Path.Combine(Path.GetTempPath(), "debug-9fc458.log");
#region agent log
internal static void Write(string hypothesisId, string location, string message, object? data = null)
{
try
{
var root = new JsonObject
{
["sessionId"] = SessionId,
["hypothesisId"] = hypothesisId,
["location"] = location,
["message"] = message,
["timestamp"] = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
["runId"] = Environment.GetEnvironmentVariable("WORKSHOP_UPLOADER_DEBUG_RUN") ?? "repro-1",
};
if (data != null)
{
root["data"] = JsonSerializer.SerializeToNode(data, data.GetType());
}
File.AppendAllText(LogPath, root.ToJsonString(new JsonSerializerOptions { WriteIndented = false }) + Environment.NewLine);
}
catch
{
// never break startup
}
}
#endregion
}