Last active
December 1, 2017 11:25
-
-
Save mahmut-gundogdu/3519a001c473a9cb5d43510fa646cd2a to your computer and use it in GitHub Desktop.
Log kütüpanesi soyutlama için bir örnek.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace KYGM.Web.UI.Infrastructure | |
{ | |
//Kaynak: https://blog.tonysneed.com/2011/10/09/using-nlog-with-dependency-injection/ | |
//Amaç: Decouple from logger framework | |
public interface ILogService | |
{ | |
bool IsDebugEnabled { get; } | |
bool IsErrorEnabled { get; } | |
bool IsFatalEnabled { get; } | |
bool IsInfoEnabled { get; } | |
bool IsTraceEnabled { get; } | |
bool IsWarnEnabled { get; } | |
void Debug(Exception exception); | |
void Debug(string format, params object[] args); | |
void Debug(Exception exception, string format, params object[] args); | |
void Error(Exception exception); | |
void Error(string format, params object[] args); | |
void Error(Exception exception, string format, params object[] args); | |
void Fatal(Exception exception); | |
void Fatal(string format, params object[] args); | |
void Fatal(Exception exception, string format, params object[] args); | |
void Info(Exception exception); | |
void Info(string format, params object[] args); | |
void Info(Exception exception, string format, params object[] args); | |
void Trace(Exception exception); | |
void Trace(string format, params object[] args); | |
void Trace(Exception exception, string format, params object[] args); | |
void Warn(Exception exception); | |
void Warn(string format, params object[] args); | |
void Warn(Exception exception, string format, params object[] args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NLog; | |
namespace KYGM.Web.UI.Infrastructure | |
{ | |
public class LogService : Logger, ILogService | |
{ | |
//what is this: https://github.com/NLog/NLog/wiki/Tutorial#creating-loggers | |
private const string LoggerName = "NLogLogger"; | |
public static ILogService GetLoggingService() | |
{ | |
ILogService logger = (ILogService)LogManager.GetLogger(LoggerName, typeof(LogService)); | |
return logger; | |
} | |
void ILogService.Debug(Exception exception, string format, params object[] args) | |
{ | |
if (!IsDebugEnabled) return; | |
base.Debug(exception,format,args); | |
} | |
void ILogService.Error(Exception exception, string format, params object[] args) | |
{ | |
if (!IsErrorEnabled) return; | |
base.Error(exception, format, args); | |
} | |
void ILogService.Fatal(Exception exception, string format, params object[] args) | |
{ | |
if (!IsFatalEnabled) return; | |
base.Fatal(exception, format, args); | |
} | |
void ILogService.Info(Exception exception, string format, params object[] args) | |
{ | |
if (!IsInfoEnabled) return; | |
base.Info(exception, format, args); | |
} | |
void ILogService.Trace(Exception exception, string format, params object[] args) | |
{ | |
if (!IsTraceEnabled) return; | |
base.Trace(exception, format, args); | |
} | |
void ILogService.Warn(Exception exception, string format, params object[] args) | |
{ | |
if (!IsWarnEnabled) return; | |
base.Warn(exception, format, args); | |
} | |
public void Debug(Exception exception) | |
{ | |
Debug(exception, string.Empty); | |
} | |
public void Error(Exception exception) | |
{ | |
Error(exception, string.Empty); | |
} | |
public void Fatal(Exception exception) | |
{ | |
Fatal(exception, string.Empty); | |
} | |
public void Info(Exception exception) | |
{ | |
Info(exception, string.Empty); | |
} | |
public void Trace(Exception exception) | |
{ | |
Trace(exception, string.Empty); | |
} | |
public void Warn(Exception exception) | |
{ | |
Warn(exception, string.Empty); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment