This commit is contained in:
CortexCore
2024-12-25 11:35:30 +08:00
parent 5b7ac3c361
commit b12511b825
8 changed files with 100 additions and 63 deletions

View File

@@ -7,8 +7,9 @@ using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace BITKit
{
public sealed class UnityLogger:ILogger
public abstract class UnityLogger:ILogger
{
[HideInCallstack]
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
switch (logLevel)
@@ -37,15 +38,37 @@ namespace BITKit
return null;
}
}
public sealed class UnityLoggerProvider:ILoggerProvider
public sealed class UnityLogger<T>:ILogger<T>
{
public void Dispose()
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
switch (logLevel)
{
case LogLevel.Critical:
case LogLevel.Error:
if (exception is not null)
{
Debug.LogException(exception);
}
else
{
Debug.LogError($"{typeof(T).Name}:{state.ToString()}");
}
break;
default:
Debug.Log($"{typeof(T).Name}:{state.ToString()}");
break;
}
}
public ILogger CreateLogger(string categoryName)
public bool IsEnabled(LogLevel logLevel)
{
return new UnityLogger();
return true;
}
public IDisposable BeginScope<TState>(TState state) where TState : notnull
{
return null;
}
}
}