-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndividualServer.Logging.cs
More file actions
39 lines (35 loc) · 1.71 KB
/
Copy pathIndividualServer.Logging.cs
File metadata and controls
39 lines (35 loc) · 1.71 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
using System;
using System.IO;
using System.Runtime.CompilerServices;
namespace RainMeadow
{
public class InvalidProgrammerException : InvalidOperationException
{
public InvalidProgrammerException(string message) : base(message + " you goof") { }
}
public partial class RainMeadow
{
private static string TrimCaller(string callerFile) { return (callerFile = callerFile.Substring(Math.Max(callerFile.LastIndexOf(Path.DirectorySeparatorChar), callerFile.LastIndexOf(Path.AltDirectorySeparatorChar)) + 1)).Substring(0, callerFile.LastIndexOf('.')); }
private static string LogDOT() { return DateTime.Now.ToUniversalTime().TimeOfDay.ToString().Substring(0, 8); }
public static void Debug(object data, [CallerFilePath] string callerFile = "", [CallerMemberName] string callerName = "")
{
Console.WriteLine($"{LogDOT()}|{TrimCaller(callerFile)}.{callerName}:{data}");
}
public static void DebugMe([CallerFilePath] string callerFile = "", [CallerMemberName] string callerName = "")
{
Console.WriteLine($"{LogDOT()}|{TrimCaller(callerFile)}.{callerName}");
}
public static void Error(object data, [CallerFilePath] string callerFile = "", [CallerMemberName] string callerName = "")
{
Console.WriteLine($"{LogDOT()}|{TrimCaller(callerFile)}.{callerName}:{data}");
Stacktrace();
}
public static void Stacktrace()
{
var stacktrace = Environment.StackTrace;
stacktrace = stacktrace.Substring(stacktrace.IndexOf('\n') + 1);
stacktrace = stacktrace.Substring(stacktrace.IndexOf('\n'));
Console.WriteLine(stacktrace);
}
}
}