This commit is contained in:
CortexCore
2025-01-12 11:13:19 +08:00
parent 01e7e4e35e
commit 01b3d1be43
26 changed files with 387 additions and 336 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
#endif
@@ -15,44 +17,40 @@ namespace BITKit
OnLog = null;
OnException = null;
OnWarning = null;
OnSetConsoleColor = null;
OnNextLine = null;
}
#endif
public static event Action<string> OnLog;
public static event Action<string,Type> OnLogCallback;
public static event Action<Exception> OnException;
public static event Action<Exception,Type> OnExceptionCallback;
public static event Action<string> OnWarning;
public static event Action<string,Type> OnWarningCallback;
public static event Action<ConsoleColor> OnSetConsoleColor;
public static event Action OnNextLine;
private static Type currentType;
#if UNITY_5_3_OR_NEWER
//[HideInCallstack]
[HideInCallstack]
#endif
public static void Log(object x, ConsoleColor color = ConsoleColor.White)
public static void Log(object x)
{
OnSetConsoleColor?.Invoke(color);
OnLog?.Invoke(x?.ToString());
OnLogCallback?.Invoke(x?.ToString(),currentType);
if (OnLog is null)
{
BITApp.ServiceProvider.GetRequiredService<ILogger<BITApp>>().LogInformation(x.ToString());
}
else
{
OnLog?.Invoke(x?.ToString());
}
}
#if UNITY_5_3_OR_NEWER
[HideInCallstack]
#endif
public static void Log<T>(object x, ConsoleColor color = ConsoleColor.White)
public static void Log<T>(object x)
{
if (currentType != typeof(T))
if (OnLog is null)
{
OnNextLine?.Invoke();
BITApp.ServiceProvider.GetRequiredService<ILogger<T>>().LogInformation(x.ToString());
}
else
{
OnLog?.Invoke(x?.ToString());
}
#if NET5_0_OR_GREATER
Log($"[{DateTime.Now}]{typeof(T).Name}:{x}");
#else
Log($"<color=#add8e6ff><b>{typeof(T).Name}</b></color>:{x}");
#endif
currentType = typeof(T);
}
#if UNITY_5_3_OR_NEWER
[HideInCallstack]