using System;
using System.Runtime.CompilerServices;
using NLog;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 로거 Logger
/// <summary>
/// 로거
/// </summary>
private static Logger _logger { get; set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 로거 설정하기- SetLogger()
/// <summary>
/// 로거 설정하기
/// </summary>
private static void SetLogger()
{
_logger = LogManager.GetCurrentClassLogger();
}
#endregion
#region 추적 로그 작성하기 - LogTrace(message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 추적 로그 작성하기
/// </summary>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogTrace
(
string message,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Trace, null, message)
{
Exception = null
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 디버그 로그 작성하기 - LogDebug(message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 디버그 로그 작성하기
/// </summary>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogDebug
(
string message,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Debug, null, message)
{
Exception = null
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 정보 로그 작성하기 - LogInfo(message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 정보 로그 작성하기
/// </summary>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogInfo
(
string message,
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0,
[CallerMemberName] string memberName = ""
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Info, null, message)
{
Exception = null
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 경고 로그 작성하기 - LogWarn(message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 경고 로그 작성하기
/// </summary>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogWarn
(
string message,
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0,
[CallerMemberName] string memberName = ""
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Warn, null, message)
{
Exception = null
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 에러 로그 작성하기 - LogError(message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 에러 로그 작성하기
/// </summary>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogError
(
string message,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Error, null, message)
{
Exception = null
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 에러 로그 작성하기 - LogError(exception, message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 에러 로그 작성하기
/// </summary>
/// <param name="exception">예외</param>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogError
(
Exception exception,
string message,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Error, null, message)
{
Exception = exception
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 치명적 에러 로그 작성하기 - LogFatal(message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 치명적 에러 로그 작성하기
/// </summary>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogFatal
(
string message,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Fatal, null, message)
{
Exception = null
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 치명적 에러 로그 작성하기 - LogFatal(exception, message, sourceFilePath, sourceLineNumber, memberName)
/// <summary>
/// 치명적 에러 로그 작성하기
/// </summary>
/// <param name="exception">예외</param>
/// <param name="message">메시지</param>
/// <param name="filePath">소스 파일 경로</param>
/// <param name="lineNumber">소스 라인 번호</param>
/// <param name="memberName">멤버명</param>
private static void LogFatal
(
Exception exception,
string message,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0
)
{
LogEventInfo logEventInfo = new LogEventInfo(LogLevel.Fatal, null, message)
{
Exception = exception
};
logEventInfo.Properties["filePath" ] = sourceFilePath;
logEventInfo.Properties["lineNumber"] = sourceLineNumber;
logEventInfo.Properties["memberName"] = memberName;
_logger.Log(logEventInfo);
}
#endregion
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
SetLogger();
LogTrace("추적 로그");
LogDebug("디버그 로그");
LogInfo("정보 로그");
LogWarn("경로 로그");
LogError("에러 로그");
LogError(new ArgumentNullException("test"), "에러 로그");
LogError("치명적 에러 로그");
LogError(new ArgumentNullException("test"), "치명적 에러 로그");
}
#endregion
}
}