本文整理汇总了C#中ErrorLog.Save方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorLog.Save方法的具体用法?C# ErrorLog.Save怎么用?C# ErrorLog.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorLog
的用法示例。
在下文中一共展示了ErrorLog.Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogError
/// <summary>
/// 记录错误日志
/// </summary>
/// <param name="module">所属模块</param>
/// <param name="ex">异常</param>
/// <param name="extraData">附加数据</param>
/// <returns></returns>
public static bool LogError(string module, Exception ex, object extraData = null)
{
var extraDataStr = string.Empty;
if (extraData != null) {
extraDataStr = JsonConvert.SerializeObject(extraData);
}
var log = new ErrorLog() {
Module = module,
ExceptionType = ex.GetType().FullName,
ExceptionDesc = ex.GetMessages(),
ExceptionCode = "500",
ThreadStack = ex.GetStackTraces(),
ExtraData = extraDataStr
};
if (HttpContext.Current != null) {
var loginUser = SecurityContext.User;
if (loginUser != null) {
log.Creator = loginUser.LoginId + "|" + loginUser.Name;
}
}
return log.Save();
}
示例2: Insert
public void Insert(string UserName,string FormName,DateTime? ErrorTime,string ApplicationName,string ErrorContent,string ErrorCode)
{
ErrorLog item = new ErrorLog();
item.UserName = UserName;
item.FormName = FormName;
item.ErrorTime = ErrorTime;
item.ApplicationName = ApplicationName;
item.ErrorContent = ErrorContent;
item.ErrorCode = ErrorCode;
item.Save(UserName);
}
示例3: Update
public void Update(int ErrorId,string UserName,string FormName,DateTime? ErrorTime,string ApplicationName,string ErrorContent,string ErrorCode)
{
ErrorLog item = new ErrorLog();
item.MarkOld();
item.IsLoaded = true;
item.ErrorId = ErrorId;
item.UserName = UserName;
item.FormName = FormName;
item.ErrorTime = ErrorTime;
item.ApplicationName = ApplicationName;
item.ErrorContent = ErrorContent;
item.ErrorCode = ErrorCode;
item.Save(UserName);
}
示例4: Insert
public void Insert(DateTime DateX,string Thread,string Level,string Logger,string Message,string Exception)
{
ErrorLog item = new ErrorLog();
item.DateX = DateX;
item.Thread = Thread;
item.Level = Level;
item.Logger = Logger;
item.Message = Message;
item.Exception = Exception;
item.Save(UserName);
}
示例5: Update
public void Update(int Id,DateTime DateX,string Thread,string Level,string Logger,string Message,string Exception)
{
ErrorLog item = new ErrorLog();
item.MarkOld();
item.IsLoaded = true;
item.Id = Id;
item.DateX = DateX;
item.Thread = Thread;
item.Level = Level;
item.Logger = Logger;
item.Message = Message;
item.Exception = Exception;
item.Save(UserName);
}
示例6: OnException
public void OnException(ExceptionContext filterContext)
{
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
// If custom errors are disabled, we need to let the normal ASP.NET exception handler
// execute so that the user can see useful debugging information.
if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
{
return;
}
var exception = filterContext.Exception;
// If this is not an HTTP 500 (for example, if somebody throws an HTTP 404 from an action method),
// ignore it.
if (new HttpException(null, exception).GetHttpCode() != 500)
{
return;
}
var controller = filterContext.Controller as Controller;
if (controller == null || filterContext.ExceptionHandled)
return;
if (exception == null)
return;
var controllerName = (string)filterContext.RouteData.Values["controller"];
var actionName = (string)filterContext.RouteData.Values["action"];
var handleErrorInfo = new HandleErrorInfo(exception, (string)controllerName, (string)actionName);
var model = new ViewDataDictionary<HandleErrorInfo>(handleErrorInfo);
try
{
var errorLog = new ErrorLog()
{
Action = actionName,
Controller = controllerName,
ExceptionMessage = filterContext.Exception.Message,
ExceptionSource = filterContext.Exception.Source,
ExceptionTargetSite = filterContext.Exception.TargetSite.DeclaringType.Name + '.' +
filterContext.Exception.TargetSite.Name,
ExceptionType = filterContext.Exception.GetType().Name,
StackTrace = filterContext.Exception.StackTrace
};
errorLog.Save();
}
catch (Exception e)
{
LogManager.GetLogger(GetType()).Fatal("Unable to Log Exception : ", e);
LogManager.GetLogger(GetType()).Fatal("Original Exception Was : ", filterContext.Exception);
}
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.Result = new PartialViewResult()
{
ViewData = model,
ViewName = "CustomError"
};
}
else
{
filterContext.Result = new ViewResult()
{
ViewData = model,
ViewName = "CustomError"
};
}
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = 500;
// Certain versions of IIS will sometimes use their own error page when
// they detect a server error. Setting this property indicates that we
// want it to try to render ASP.NET MVC's error page instead.
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
}