2018-05-22 10:11:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using NLog.Extensions.Logging;
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
namespace Core.Helper
|
|
|
|
|
{
|
|
|
|
|
public class LogHelper
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
private readonly ILogger<LogHelper> log;
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public LogHelper(ILogger<LogHelper> logger)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
log = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public void DoLogInfo(string message)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
if (log.IsEnabled(LogLevel.Information)) log.LogInformation(message);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public void DoLogWarn(string message)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
if (log.IsEnabled(LogLevel.Warning)) log.LogWarning(message);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public void DoLogError(string message)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
if (log.IsEnabled(LogLevel.Error)) log.LogError(message);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public void DoLogDebug(string message)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
if (log.IsEnabled(LogLevel.Debug)) log.LogDebug(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|