2024-11-03 16:38:17 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using UnityEngine;
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
|
|
|
|
|
|
namespace BITKit
|
|
|
|
{
|
2024-12-25 11:35:30 +08:00
|
|
|
public sealed class UnityLogger<T>:ILogger<T>
|
2024-11-03 16:38:17 +08:00
|
|
|
{
|
2025-01-12 11:13:19 +08:00
|
|
|
[HideInCallstack]
|
2024-12-25 11:35:30 +08:00
|
|
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
2024-11-03 16:38:17 +08:00
|
|
|
{
|
2024-12-25 11:35:30 +08:00
|
|
|
switch (logLevel)
|
|
|
|
{
|
|
|
|
case LogLevel.Critical:
|
|
|
|
case LogLevel.Error:
|
|
|
|
if (exception is not null)
|
|
|
|
{
|
|
|
|
Debug.LogException(exception);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-03-09 13:38:23 +08:00
|
|
|
Debug.LogError($"{typeof(T).CSharpName()}:{state.ToString()}");
|
2024-12-25 11:35:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2025-03-09 13:38:23 +08:00
|
|
|
Debug.Log($"<b>{typeof(T).CSharpName()}</b>:{state.ToString()}");
|
2024-12-25 11:35:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsEnabled(LogLevel logLevel)
|
|
|
|
{
|
|
|
|
return true;
|
2024-11-03 16:38:17 +08:00
|
|
|
}
|
|
|
|
|
2024-12-25 11:35:30 +08:00
|
|
|
public IDisposable BeginScope<TState>(TState state) where TState : notnull
|
2024-11-03 16:38:17 +08:00
|
|
|
{
|
2024-12-25 11:35:30 +08:00
|
|
|
return null;
|
2024-11-03 16:38:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|