Ejemplo n.º 1
0
        private static void SaveLog(string issuedBy, SeverityEnum severity, SystemError sys, string issuedMessage)
        {
            if (issuedMessage.Length >= 4000)
            {
                issuedMessage = issuedMessage.Substring(0, 4000);
            }

            var options = new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            };

            using (var exceptionLogScope = new TransactionScope(TransactionScopeOption.RequiresNew, options))
            {
                using (var container = new TransactionModelContainer())
                {
                    container.ErrorLogs.AddObject(new ErrorLog
                    {
                        IssuedBy        = issuedBy,
                        IssuedDate      = DateTime.Now,
                        IssuedMessage   = issuedMessage,
                        Severity        = (byte)severity,
                        SystemErrorId   = (byte)sys,
                        SystemErrorName = sys.ToString(),
                    });

                    container.SaveChanges();
                    exceptionLogScope.Complete();
                }
            }
        }
Ejemplo n.º 2
0
 public static void ConfigureExceptionHandling(this IApplicationBuilder app)
 {
     app.UseExceptionHandler(err =>
     {
         err.Run(async context =>
         {
             context.Response.ContentType = "application/json";
             context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
             var contextFeature           = context.Features.Get <IExceptionHandlerFeature>();
             if (contextFeature != null)
             {
                 var error = new SystemError()
                 {
                     ExceptionMessage           = contextFeature.Error.Message,
                     InnerExceptionErrorMessage = contextFeature.Error.InnerException?.Message
                 };
                 await context.Response.WriteAsync(error.ToString());
             }
         });
     });
 }
Ejemplo n.º 3
0
        private static void SaveLog(string issuedBy, SeverityEnum severity, SystemError sys, string issuedMessage)
        {
            if (issuedMessage.Length >= 4000)
            {
                issuedMessage = issuedMessage.Substring(0, 4000);
            }

            var options = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted };
            using (var exceptionLogScope = new TransactionScope(TransactionScopeOption.RequiresNew, options))
            {
                using (var container = new TransactionModelContainer())
                {
                    container.ErrorLogs.AddObject(new ErrorLog
                            {
                                IssuedBy = issuedBy,
                                IssuedDate = DateTime.Now,
                                IssuedMessage = issuedMessage,
                                Severity = (byte)severity,
                                SystemErrorId = (byte)sys,
                                SystemErrorName = sys.ToString(),
                            });

                    container.SaveChanges();
                    exceptionLogScope.Complete();
                }
            }
        }
Ejemplo n.º 4
0
 public RspError(SystemError error)
 {
     switch (error) {
         case SystemError.NoPermission: {
                 this.Name = error.ToString();
                 this.Message = "没有权限";
             }
             break;
         case SystemError.RunTimeError: {
                 this.Name = error.ToString();
                 this.Message = "运行环境出错";
             }
             break;
         case SystemError.SessionTimeout: {
                 this.Name = error.ToString();
                 this.Message = "会话过期";
             }
             break;
         case SystemError.ServiceException: {
                 this.Name = error.ToString();
                 this.Message = "服务端方法异常";
             }
             break;
         case SystemError.NoMatchService: {
                 this.Name = error.ToString();
                 this.Message = "没有匹配到相应的服务";
             }
             break;
         case SystemError.NoMatchParam: {
                 this.Name = error.ToString();
                 this.Message = "没有匹配到参数";
             }
             break;
         case SystemError.ParamIndex: {
                 this.Name = error.ToString();
                 this.Message = "参数索引顺序错误";
             }
             break;
         default: {
                 this.Name = SystemError.UnKnown.ToString();
                 this.Message = "未知错误";
             }
             break;
     }
 }
Ejemplo n.º 5
0
 public RspError(SystemError error, string message)
 {
     this.Name = error.ToString();
     this.Message = message;
 }