You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
3.6 KiB
C#
121 lines
3.6 KiB
C#
using System;
|
|
using System.Data;
|
|
using DSWeb.Models;
|
|
using DSWeb.EntityDA;
|
|
|
|
|
|
namespace DSWeb.Log
|
|
{
|
|
public class Logger
|
|
{
|
|
public readonly static Logger Instance = new Logger();
|
|
private LogTypes _log_type;
|
|
|
|
public Logger()
|
|
{
|
|
}
|
|
|
|
|
|
public void WriteLog(LogEntity tempLogEntity)
|
|
{
|
|
LogDA logDA = new LogDA();
|
|
LogEntity logEntity = tempLogEntity;
|
|
|
|
int iResult = logDA.InsertLog(tempLogEntity);
|
|
}
|
|
//#region 获取详细日志SQL操作
|
|
///// <summary>
|
|
///// 获取详细日志SQL操作
|
|
///// INSERT-"INSERT INTO {0} ({1}) VALUES ({2})" @{0}-所要插入记录的表;{1}-记录新值@
|
|
///// DELETE-"将 {0} 记录 删除" @{0}-记录所删记录名称@
|
|
///// </summary>
|
|
///// <param name="logType"></param>
|
|
///// <returns></returns>
|
|
//public string GetLogTemplate(LogTypes logType)
|
|
//{
|
|
// _log_type = logType;
|
|
// string strSql = "";
|
|
// switch (_log_type)
|
|
// {
|
|
// case LogTypes.INSERT:
|
|
// //strSql = " INSERT INTO {0} ({1}) VALUES ({2})";
|
|
// strSql = " LOGCONTENT = '{}'"
|
|
// break;
|
|
// case LogTypes.DELETE:
|
|
// strSql = " DELETE FROM {0} WHERE 0 > 1 OR {2} ";
|
|
// break;
|
|
// default:
|
|
// strSql = " ";
|
|
// break;
|
|
// }
|
|
|
|
// return strSql;
|
|
//}
|
|
//#endregion
|
|
|
|
#region 获取日志详细操作记录内容模板
|
|
/// <summary>
|
|
/// 获取日志详细操作记录内容模板
|
|
/// UPDATE-"将 {0} 值 {1} 更改为 {2}" @{0}-记录所更新页面字段名称;{1}-记录原值;{2}-记录更新值@
|
|
/// INSERT-"增加 {0} 值 {1} " @{0}-记录所插入页面字段名称;{1}-记录新值@
|
|
/// DELETE-"将 {0} 记录 删除" @{0}-记录所删记录名称@
|
|
/// </summary>
|
|
/// <param name="logType"></param>
|
|
/// <returns></returns>
|
|
public string GetLogContentTemplate(LogTypes logType)
|
|
{
|
|
_log_type = logType;
|
|
string strSql = "";
|
|
switch (_log_type)
|
|
{
|
|
case LogTypes.UPDATE:
|
|
strSql = " 将 {0} 值 {1} 更改为 {2} ";
|
|
break;
|
|
case LogTypes.INSERT:
|
|
strSql = " 增加 {0} 值 {1} ";
|
|
break;
|
|
case LogTypes.DELETE:
|
|
strSql = " 将 {0} 记录 {1} 删除 ";
|
|
break;
|
|
default:
|
|
strSql = " ";
|
|
break;
|
|
}
|
|
|
|
return strSql;
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 日志类型(读写属性)
|
|
/// </summary>
|
|
public LogTypes LogType
|
|
{
|
|
get { return _log_type; }
|
|
set { _log_type = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日志类型
|
|
/// </summary>
|
|
public enum LogTypes
|
|
{
|
|
UPDATE = 0,//更新操作
|
|
INSERT = 1,//插入操作
|
|
DELETE = 2,//删除操作
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日志消息类型
|
|
/// </summary>
|
|
public enum LogMessageTypes
|
|
{
|
|
Info, // 通知消息
|
|
Warning, // 警告消息
|
|
Excepiton, // 异常消息
|
|
Error, // 非致命错误消息
|
|
Fatal, // 致命错误消息
|
|
}
|
|
}
|
|
}
|