forked from IvanMurzak/Unity-MCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogEntry.cs
More file actions
63 lines (57 loc) · 2.43 KB
/
LogEntry.cs
File metadata and controls
63 lines (57 loc) · 2.43 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
/*
┌──────────────────────────────────────────────────────────────────┐
│ Author: Ivan Murzak (https://github.com/IvanMurzak) │
│ Repository: GitHub (https://github.com/IvanMurzak/Unity-MCP) │
│ Copyright (c) 2025 Ivan Murzak │
│ Licensed under the Apache License, Version 2.0. │
│ See the LICENSE file in the project root for more information. │
└──────────────────────────────────────────────────────────────────┘
*/
#nullable enable
using System;
using UnityEngine;
namespace com.IvanMurzak.Unity.MCP
{
public class LogEntry
{
public LogType LogType { get; set; }
public string Message { get; set; }
public DateTime Timestamp { get; set; }
public string? StackTrace { get; set; }
public LogEntry()
{
LogType = LogType.Log;
Message = string.Empty;
Timestamp = DateTime.Now;
StackTrace = null;
}
public LogEntry(LogType logType, string message)
{
LogType = logType;
Message = message;
Timestamp = DateTime.Now;
StackTrace = null;
}
public LogEntry(LogType logType, string message, string? stackTrace = null)
{
LogType = logType;
Message = message;
Timestamp = DateTime.Now;
StackTrace = string.IsNullOrEmpty(stackTrace) ? null : stackTrace;
}
public LogEntry(LogType logType, string message, DateTime timestamp, string? stackTrace = null)
{
LogType = logType;
Message = message;
Timestamp = timestamp;
StackTrace = string.IsNullOrEmpty(stackTrace) ? null : stackTrace;
}
public override string ToString() => ToString(includeStackTrace: false);
public string ToString(bool includeStackTrace)
{
return includeStackTrace && !string.IsNullOrEmpty(StackTrace)
? $"{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{LogType}] {Message}\nStack Trace:\n{StackTrace}"
: $"{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{LogType}] {Message}";
}
}
}