78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
#if UNITY_5_3_OR_NEWER
|
|
using UnityEngine;
|
|
#endif
|
|
|
|
namespace BITKit
|
|
{
|
|
public static class BIT4Log
|
|
{
|
|
#if UNITY_EDITOR && UNITY_5_3_OR_NEWER
|
|
[RuntimeInitializeOnLoadMethod]
|
|
private static void Reload()
|
|
{
|
|
OnLog = null;
|
|
OnException = null;
|
|
OnWarning = null;
|
|
OnNextLine = null;
|
|
}
|
|
#endif
|
|
public static event Action<string> OnLog;
|
|
public static event Action<Exception> OnException;
|
|
public static event Action<string> OnWarning;
|
|
public static event Action OnNextLine;
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void Log(object x)
|
|
{
|
|
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)
|
|
{
|
|
if (OnLog is null)
|
|
{
|
|
BITApp.ServiceProvider.GetRequiredService<ILogger<T>>().LogInformation(x.ToString());
|
|
}
|
|
else
|
|
{
|
|
OnLog?.Invoke(x?.ToString());
|
|
}
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void LogException(Exception e)
|
|
{
|
|
OnException?.Invoke(e);
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void Warning(object x)
|
|
{
|
|
OnWarning?.Invoke(x.ToString());
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void Warning<T>(object x)
|
|
{
|
|
Warning($"<color=#ffa500ff><b>{typeof(T).Name}</b></color>:{x}");
|
|
}
|
|
}
|
|
}
|