zz
This commit is contained in:
114
GlobalTorch/TorchLogger.cs
Normal file
114
GlobalTorch/TorchLogger.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Global.Shared.Logging;
|
||||
using NLog;
|
||||
|
||||
namespace Global
|
||||
{
|
||||
public class TorchLogger : LogFormatter, IPluginLogger
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public TorchLogger(string pluginName) : base("")
|
||||
{
|
||||
_logger = LogManager.GetLogger(pluginName);
|
||||
}
|
||||
|
||||
public bool IsTraceEnabled => _logger.IsTraceEnabled && GlobalPlugin.IsLoggingLevel(LoggingLevel.Trace);
|
||||
public bool IsDebugEnabled => _logger.IsDebugEnabled && GlobalPlugin.IsLoggingLevel(LoggingLevel.Debug);
|
||||
public bool IsInfoEnabled => _logger.IsInfoEnabled && GlobalPlugin.IsLoggingLevel(LoggingLevel.Info);
|
||||
public bool IsWarningEnabled => _logger.IsWarnEnabled && GlobalPlugin.IsLoggingLevel(LoggingLevel.Warning);
|
||||
public bool IsErrorEnabled => _logger.IsErrorEnabled && GlobalPlugin.IsLoggingLevel(LoggingLevel.Error);
|
||||
public bool IsCriticalEnabled => _logger.IsFatalEnabled && GlobalPlugin.IsLoggingLevel(LoggingLevel.Fatal);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Trace(Exception ex, string message, params object[] data)
|
||||
{
|
||||
if (!IsTraceEnabled)
|
||||
return;
|
||||
|
||||
_logger.Trace(Format(ex, message, data));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Debug(Exception ex, string message, params object[] data)
|
||||
{
|
||||
if (!IsDebugEnabled)
|
||||
return;
|
||||
|
||||
_logger.Debug(Format(ex, message, data));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Info(Exception ex, string message, params object[] data)
|
||||
{
|
||||
if (!IsInfoEnabled)
|
||||
return;
|
||||
|
||||
_logger.Info(Format(ex, message, data));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Warning(Exception ex, string message, params object[] data)
|
||||
{
|
||||
if (!IsWarningEnabled)
|
||||
return;
|
||||
|
||||
_logger.Warn(Format(ex, message, data));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Error(Exception ex, string message, params object[] data)
|
||||
{
|
||||
if (!IsErrorEnabled)
|
||||
return;
|
||||
|
||||
_logger.Error(Format(ex, message, data));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Critical(Exception ex, string message, params object[] data)
|
||||
{
|
||||
if (!IsCriticalEnabled)
|
||||
return;
|
||||
|
||||
_logger.Fatal(Format(ex, message, data));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Trace(string message, params object[] data)
|
||||
{
|
||||
Trace(null, message, data);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Debug(string message, params object[] data)
|
||||
{
|
||||
Debug(null, message, data);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Info(string message, params object[] data)
|
||||
{
|
||||
Info(null, message, data);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Warning(string message, params object[] data)
|
||||
{
|
||||
Warning(null, message, data);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Error(string message, params object[] data)
|
||||
{
|
||||
Error(null, message, data);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Critical(string message, params object[] data)
|
||||
{
|
||||
Critical(null, message, data);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user