记录日志BUG——解决登录前不能记录日志 LOg4 net

/// <summary>
/// 记录操作日志
/// </summary>
/// <param name="ActionType">动作类型</param>
/// <param name="Key">操作数据关键字</param>
/// <param name="IsSuccess">是否成功</param>
/// <param name="Exception">异常信息</param>
/// <param name="ModuleName">模块名称 </param>
/// <param name="Entities">数据</param>
protected void LogAction(BaseEnum.ActionType ActionType, string Key, bool IsSuccess, Exception Exception, string ModuleName, params EntityBase[] Entities)
{
if (ConfigurationManager.AppSettings["OperationLog_Enable"] == "1")
{
SLogEntity LogEntity = new SLogEntity();

LogEntity.Thekey = Key;

LogEntity.Actiontype = ((int)ActionType).ToString();

if (Exception != null)
{
LogEntity.ActionData = "Message:\r\n" + Exception.Message + "\r\nStackTrace:\r\n+" + Exception.StackTrace + "\r\nSource:\r\n" + Exception.Source;
}
LogEntity.OperatorDate = DateTime.Now;
LogEntity.Ip = Request.UserHostAddress;
LogEntity.ActionResult = IsSuccess ? "1" : "0";

//这里应该是-1,不存在为-1,存在为就不是-1
if (ModuleName.IndexOf("注册") != -1)
{
LogEntity.OperatorId = "";
LogEntity.OperatorName = "";
}
else
{
LogEntity.OperatorId = CurrentUser.Id;
LogEntity.OperatorName = CurrentUser.Email;
}

LogEntity.Id = Guid.NewGuid().ToString();

 

LogEntity.Dataxml = "";

foreach (EntityBase entity in Entities)
{

//LogEntity.Dataxml += SerializeHelper.SerializeObjectToString(entity);

LogEntity.Dataxml += "\r\n\r\n";

}
//string strURL = Request.Url.ToString().Substring(Request.Url.ToString().LastIndexOf("/") + 1);
//SModuleEntity enModule = SModule.GetLeftModuleInfoByUrl(strURL);
//if (!string.IsNullOrEmpty(enModule.Id))
//{
LogEntity.ModuleId = Guid.NewGuid().ToString(); //enModule.Id;
LogEntity.ModuleName = ModuleName; //enModule.Modulename;
//}
SOperationlog.InsertSOperationlog(LogEntity);


}

 

}

posted @ 2012-03-06 11:35  cn_king  阅读(332)  评论(0编辑  收藏  举报