PTMagic/Core/Helper/LogHelper.cs

43 lines
966 B
C#
Raw Normal View History

2018-05-22 10:11:50 +02:00
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace Core.Helper
{
public class LogHelper
{
2018-05-22 10:11:50 +02:00
private readonly ILogger<LogHelper> log;
public LogHelper(ILogger<LogHelper> logger)
{
2018-05-22 10:11:50 +02:00
log = logger;
}
public void DoLogInfo(string message)
{
2018-05-22 10:11:50 +02:00
if (log.IsEnabled(LogLevel.Information)) log.LogInformation(message);
}
public void DoLogWarn(string message)
{
2018-05-22 10:11:50 +02:00
if (log.IsEnabled(LogLevel.Warning)) log.LogWarning(message);
}
public void DoLogError(string message)
{
2018-05-22 10:11:50 +02:00
if (log.IsEnabled(LogLevel.Error)) log.LogError(message);
}
public void DoLogCritical(string message, System.Exception ex)
{
2018-05-22 10:11:50 +02:00
if (log.IsEnabled(LogLevel.Critical)) log.LogCritical(ex, message);
}
public void DoLogDebug(string message)
{
2018-05-22 10:11:50 +02:00
if (log.IsEnabled(LogLevel.Debug)) log.LogDebug(message);
}
}
}