270 lines
8.1 KiB
C#
270 lines
8.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using log4net;
|
|
using System.Data;
|
|
|
|
namespace NP.Base
|
|
{
|
|
public class Logger
|
|
{
|
|
private static readonly ILog debugLog = log4net.LogManager.GetLogger("Debug");
|
|
private static readonly ILog errorLog = log4net.LogManager.GetLogger("Error");
|
|
private static readonly ILog tryErrorLog = log4net.LogManager.GetLogger("TryError");
|
|
private static readonly ILog queryLog = log4net.LogManager.GetLogger("Query");
|
|
private static readonly ILog warnLog = log4net.LogManager.GetLogger("Warn");
|
|
private static readonly ILog deleteLog = log4net.LogManager.GetLogger("Delete");
|
|
|
|
/// <summary>
|
|
/// 데이타 테이블 디버깅
|
|
/// </summary>
|
|
/// <param name="dt"></param>
|
|
/// <param name="flag"></param>
|
|
public static void Debug(DataTable dt, string flag)
|
|
{
|
|
|
|
string title = "데이타 테이블 디버깅";
|
|
|
|
int rowCount = 0;
|
|
string header = "";
|
|
|
|
rowCount = dt.Rows.Count;
|
|
|
|
foreach (DataColumn column in dt.Columns)
|
|
{
|
|
header += column.ColumnName + ", ";
|
|
}
|
|
|
|
if (header.Length > 0)
|
|
header = header.Substring(0, header.Length - 2);
|
|
|
|
header = "COLUMN { " + header + " }";
|
|
|
|
if (flag == "debug")
|
|
{
|
|
System.Diagnostics.Debug.WriteLine("");
|
|
System.Diagnostics.Debug.WriteLine(title);
|
|
System.Diagnostics.Debug.WriteLine("");
|
|
System.Diagnostics.Debug.WriteLine("ROW COUNT : " + rowCount);
|
|
System.Diagnostics.Debug.WriteLine(header);
|
|
}
|
|
else if (flag == "log")
|
|
{
|
|
Debug("");
|
|
Debug(title);
|
|
Debug("");
|
|
Debug("ROW COUNT : " + rowCount);
|
|
Debug(header);
|
|
}
|
|
|
|
int j = 0;
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
string content = "";
|
|
|
|
for (int i = 0; i < row.ItemArray.Length; i++)
|
|
{
|
|
content += row.ItemArray[i].ToString() + ", ";
|
|
}
|
|
|
|
if (content.Length > 0)
|
|
content = content.Substring(0, content.Length - 2);
|
|
|
|
content = "ROW[" + j + "] { " + content + " }";
|
|
|
|
if (flag == "debug")
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(content);
|
|
}
|
|
else if (flag == "log")
|
|
{
|
|
Debug(content);
|
|
}
|
|
|
|
j++;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 실제 데이터 삭제이력로그를 남긴다.
|
|
/// </summary>
|
|
/// <param name="msg">삭제정보</param>
|
|
public static void Delete(string msg)
|
|
{
|
|
using (log4net.NDC.Push("Deleting"))
|
|
{
|
|
deleteLog.Fatal(msg);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 치명적이지 않은 경고로그를 남긴다.
|
|
/// </summary>
|
|
/// <param name="msg">메세지</param>
|
|
public static void Warn(string msg)
|
|
{
|
|
using (log4net.NDC.Push("Warning"))
|
|
{
|
|
warnLog.Warn(msg);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 치명적이지 않은 경고로그를 남긴다.
|
|
/// </summary>
|
|
/// <param name="msg">메세지</param>
|
|
public static void Warn(object msg)
|
|
{
|
|
using (log4net.NDC.Push("Warning"))
|
|
{
|
|
warnLog.Warn(msg.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 치명적인 오류로그를 남긴다.
|
|
/// </summary>
|
|
/// <param name="e">예외 클래스</param>
|
|
/// <param name="msg">메세지</param>
|
|
public static void Error(object msg, Exception e)
|
|
{
|
|
using (log4net.NDC.Push("Error"))
|
|
{
|
|
errorLog.Error(msg.ToString(), e);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 치명적인 오류로그를 남긴다.
|
|
/// </summary>
|
|
/// <param name="e">예외 클래스</param>
|
|
/// <param name="msg">메세지</param>
|
|
public static void TryError(object msg, Exception e)
|
|
{
|
|
using (log4net.NDC.Push("TryError"))
|
|
{
|
|
tryErrorLog.Error(msg.ToString(), e);
|
|
}
|
|
}
|
|
|
|
public static void ErrorPay(object msg, Exception e)
|
|
{
|
|
using (log4net.NDC.Push("ErrorPay"))
|
|
{
|
|
errorLog.Error(msg.ToString(), e);
|
|
}
|
|
}
|
|
|
|
public static void ErrorControll(object msg, Exception e)
|
|
{
|
|
using (log4net.NDC.Push("ErrorControll"))
|
|
{
|
|
errorLog.Error(msg.ToString(), e);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 치명적인 오류로그를 남긴다.
|
|
/// </summary>
|
|
/// <param name="msg">메세지</param>
|
|
public static void Error(string msg)
|
|
{
|
|
using (log4net.NDC.Push("Error"))
|
|
{
|
|
errorLog.Error(msg);
|
|
}
|
|
}
|
|
|
|
public static void Query(string str, string flag)
|
|
{
|
|
Query("", str, flag);
|
|
}
|
|
|
|
public static void Query(string key, string str, string flag)
|
|
{
|
|
using (log4net.NDC.Push(key))
|
|
{
|
|
queryLog.Info(str);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 실행된 SQL 쿼리문을 로그로 남긴다.
|
|
/// </summary>
|
|
public static void Query(object msg)
|
|
{
|
|
using (log4net.NDC.Push("Executed Qeury"))
|
|
{
|
|
queryLog.Info(msg.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 어플리케이션 수행시 실행된 SQL 쿼리문을 로그로 남긴다.
|
|
/// </summary>
|
|
public static void Query(string msg)
|
|
{
|
|
using (log4net.NDC.Push("Executed Qeury"))
|
|
{
|
|
queryLog.Info(msg);
|
|
}
|
|
}
|
|
|
|
public static void Debug(string key, string str, string flag)
|
|
{
|
|
string title = "String 디버깅";
|
|
|
|
if (flag == "debug")
|
|
{
|
|
System.Diagnostics.Debug.WriteLine("");
|
|
System.Diagnostics.Debug.WriteLine(title);
|
|
System.Diagnostics.Debug.WriteLine(str);
|
|
}
|
|
else if (flag == "log")
|
|
{
|
|
Debug(key);
|
|
Debug(title);
|
|
Debug(str);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 디버깅을 위한 내용을 로그로 남긴다.
|
|
/// </summary>
|
|
public static void Debug(string key, object msg)
|
|
{
|
|
using (log4net.NDC.Push("Debug"))
|
|
{
|
|
debugLog.Debug(key);
|
|
debugLog.Debug(msg.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 디버깅을 위한 내용을 로그로 남긴다.
|
|
/// </summary>
|
|
public static void Debug(string key, string msg)
|
|
{
|
|
using (log4net.NDC.Push("Debug"))
|
|
{
|
|
debugLog.Debug(key);
|
|
debugLog.Debug(msg);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 디버깅을 위한 내용을 로그로 남긴다.
|
|
/// </summary>
|
|
public static void Debug(string msg)
|
|
{
|
|
using (log4net.NDC.Push("Debug"))
|
|
{
|
|
debugLog.Debug(msg);
|
|
}
|
|
}
|
|
}
|
|
}
|