46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Extensions.Logging;
|
|
using UnityEngine;
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
|
|
namespace BITKit
|
|
{
|
|
public sealed class UnityLogger<T>:ILogger<T>
|
|
{
|
|
[HideInCallstack]
|
|
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).CSharpName()}:{state.ToString()}");
|
|
}
|
|
break;
|
|
default:
|
|
Debug.Log($"<b>{typeof(T).CSharpName()}</b>:{state.ToString()}");
|
|
break;
|
|
}
|
|
}
|
|
|
|
public bool IsEnabled(LogLevel logLevel)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public IDisposable BeginScope<TState>(TState state) where TState : notnull
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|