#region
|
|
using System;
|
using CSFrameworkV5.Common;
|
using CSFrameworkV5.Core;
|
using CSFrameworkV5.DataAccess;
|
using CSFrameworkV5.Interfaces;
|
using CSFrameworkV5.Models;
|
using CSFrameworkV5.WebRef.CommonService;
|
|
#endregion
|
|
namespace CSFrameworkV5.Business
|
{
|
/// <summary>
|
/// 数据库日志
|
/// </summary>
|
public class LogDB : ILogUserOperate
|
{
|
private IBridge_Log _Log;
|
|
public LogDB()
|
{
|
_Log = CreateLogData();
|
}
|
|
private IBridge_Log CreateLogData()
|
{
|
//DB日志要测试数据库连接
|
BridgeFactory.TestConnection(true);
|
|
if (BridgeFactory.IsADODirect)
|
return new dalLog(Loginer.CurrentUser);
|
|
if (BridgeFactory.IsWCFBridge) return new WCF_OperateLog();
|
|
throw new CustomException(BridgeFactory.UNKNOW_BRIDGE_TYPE);
|
}
|
|
private string GetStr(string content, int length)
|
{
|
if (string.IsNullOrEmpty(content)) return "";
|
|
var max = content.Length;
|
if (max > length) max = length;
|
|
return content.Substring(0, max);
|
}
|
|
#region 数据日志单例
|
|
private static LogDB _Instance;
|
|
public static LogDB Log
|
{
|
get
|
{
|
if (_Instance == null) _Instance = new LogDB();
|
|
return _Instance;
|
}
|
}
|
|
#endregion;
|
|
//在数据库建张Log表,实现相应接口
|
|
#region IOperateLog Members
|
|
public void WriteLog(LogTypeSystem type, string content)
|
{
|
try
|
{
|
var log = new sys_LogOperation();
|
log.Account = Loginer.CurrentUser.Account;
|
log.MSG = GetStr(content, 98); //最长98个字符
|
log.OperationTime = DateTime.Now;
|
log.OperationType = type.ToStringEx();
|
log.FormName = "";
|
log.MenuName = "";
|
log.FormCaption = "";
|
_Log.WriteLog(log);
|
}
|
catch
|
{
|
//写日志失败,不抛出异常
|
}
|
}
|
|
public void WriteLog(LogTypeSystem type, string content,
|
string formName, string formCaption, string menuName)
|
{
|
try
|
{
|
var log = new sys_LogOperation();
|
log.Account = Loginer.CurrentUser.Account;
|
log.MSG = content;
|
log.OperationTime = DateTime.Now;
|
log.OperationType = type.ToStringEx();
|
log.FormName = formName;
|
log.FormCaption = formCaption;
|
log.MenuName = menuName;
|
_Log.WriteLog(log);
|
}
|
catch
|
{
|
//写日志失败,不抛出异常
|
}
|
}
|
|
public void ClearLog(string user, DateTime beginDate, DateTime endDate)
|
{
|
try
|
{
|
_Log.ClearLog(user, beginDate, endDate);
|
}
|
catch
|
{
|
//写日志失败,不抛出异常
|
}
|
}
|
|
public void WriteLog(string content)
|
{
|
try
|
{
|
_Log.WriteLog(content);
|
}
|
catch
|
{
|
//写日志失败,不抛出异常
|
}
|
}
|
|
public void ClearLog(DateTime beginDate, DateTime endDate)
|
{
|
try
|
{
|
_Log.ClearLog(beginDate, endDate);
|
}
|
catch
|
{
|
//写日志失败,不抛出异常
|
}
|
}
|
|
public void ClearAll()
|
{
|
try
|
{
|
_Log.ClearAll();
|
}
|
catch
|
{
|
//写日志失败,不抛出异常
|
}
|
}
|
|
#endregion
|
}
|
|
//兼容原有的DBLog类,请使用LogDB类
|
public class DBLog : LogDB
|
{
|
}
|
}
|