using System.Text;
using System.Data;
using System;
namespace Common.LogUtil
{
public static class Log
{
///
/// 记录异常信息
///
///
public static void Record(LogInformation log)
{
StringBuilder query = new StringBuilder("INSERT INTO T_SYS_DEBUG_LOG(HELPLINK,EXMESSAGE,EXSOURCE,STACKTRACE,TARGETSITE,CREATETIME,OPERATEUSER,EXTENDMESSAGE,SOURCEDEVICE,CLIENTIP) VALUES('{HELPLINK}','{EXMESSAGE}','{EXSOURCE}','{STACKTRACE}','{TARGETSITE}',getdate(),'{OPERATEUSER}','{EXTENDMESSAGE}','{SOURCEDEVICE}','{CLIENTIP}')");
query.Replace("{HELPLINK}", log.HELPLINK);
query.Replace("{EXMESSAGE}", log.EXMESSAGE);
query.Replace("{EXSOURCE}", log.EXSOURCE);
query.Replace("{STACKTRACE}", log.STACKTRACE);
query.Replace("{TARGETSITE}", log.TARGETSITE);
query.Replace("{OPERATEUSER}", log.OPERATEUSER);
query.Replace("{EXTENDMESSAGE}", log.EXTENDMESSAGE);
query.Replace("{SOURCEDEVICE}", log.SOURCEDEVICE);
query.Replace("{CLIENTIP}", log.CLIENTIP);
Data.SqlLite.SqlLiteHelper dal = new Data.SqlLite.SqlLiteHelper();
try
{
using (System.Data.IDbConnection conn = dal.OpenConnection(Common.Config.ConfigSetting.GetDBConnString(1)))
{
dal.ExecuteSql(conn, query.ToString());
}
}
catch { }
}
///
/// 获取所有消息记录
///
///
public static DataTable Read()
{
Data.SqlLite.SqlLiteHelper dal = new Data.SqlLite.SqlLiteHelper();
using (System.Data.IDbConnection conn = dal.OpenConnection(Common.Config.ConfigSetting.GetDBConnString(1)))
{
return dal.QueryReturnDataTable(conn, "SELECT * FROM T_SYS_DEBUG_LOG");
}
}
///
/// 以分页方式获取消息记录
///
/// 每页数据条数
/// 要获取数据的页码
/// 总页数
/// 总行数
///
//public static DataTable Read(int pageSize, int pageIndex, out int pageCount, out int rowCount)
//{
// string start = (pageSize * pageIndex).ToString();
// Data.SqlLite.SqlLiteHelper dal = new Data.SqlLite.SqlLiteHelper();
// using (System.Data.IDbConnection conn = dal.OpenConnection(Common.Config.ConfigSetting.GetConnectionString()))
// using (Data.SqlLite.SqlLiteRoutine routine = new Data.SqlLite.SqlLiteRoutine(conn))
// {
// rowCount = (int)routine.GetSingle("SELECT COUNT(1) FROM T_LOG");
// pageCount = (int)Math.Ceiling((decimal)(rowCount / pageSize));
// return routine.QueryReturnDataTable("SELECT * FROM T_LOG LIMIT " + start + "," + pageSize.ToString());
// }
//}
}
}