当前位置: 首页>>代码示例>>C#>>正文


C# ErrorLog.Save方法代码示例

本文整理汇总了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();
 }
开发者ID:Wangzr,项目名称:TrioFramework,代码行数:29,代码来源:Logger.cs

示例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);
	    }
开发者ID:khaha2210,项目名称:radio,代码行数:19,代码来源:ErrorLogController.cs

示例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);
	    }
开发者ID:khaha2210,项目名称:radio,代码行数:22,代码来源:ErrorLogController.cs

示例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);
        }
开发者ID:Lornestar,项目名称:pfx,代码行数:18,代码来源:ErrorLogController.cs

示例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);
        }
开发者ID:Lornestar,项目名称:pfx,代码行数:22,代码来源:ErrorLogController.cs

示例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;
        }
开发者ID:krantibandi,项目名称:PittsburghBaba,代码行数:83,代码来源:HandleCustomAttribute.cs


注:本文中的ErrorLog.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。