コード例 #1
0
ファイル: ExceptionService.cs プロジェクト: yhhno/Adhesive
        private void InternalHandle(ExceptionInfo info, Exception exception, string moduleName, string categoryName, string subcategoryName, string description, ExtraInfo extraInfo)
        {
            if (exception == null)
                return;
            try
            {
                if (AppInfoCenterConfiguration.GetConfig().ExceptionServiceConfig.Enabled)
                {
                    var strategy = GetExceptionStrategy(moduleName, info.GetType().Name, exception.GetType().Name);
                    if (strategy != null)
                    {
                        if (strategy.LocalLog)
                            LocalLog(info, exception, moduleName, categoryName, subcategoryName, description, extraInfo);
                        if (strategy.RemoteLog)
                        {
                            info.Exception = MapException(exception);
                            info.Description = description;
                            info.ExceptionTypeName = exception.GetType().FullName;
                            info.ExtraInfo = extraInfo;
                            info.ModuleName = moduleName;
                            info.CategoryName = categoryName;
                            info.SubCategoryName = subcategoryName;
                            info.ExceptionMessage = exception.Message;
                            ProcessInfo(info);
                            MongodbService.MongodbInsertService.Insert(info);
                        }

                        if (info is WebSiteUnhandledExceptionInfo && HttpContext.Current != null)
                        {
                            HttpContext.Current.Response.Clear();

                            //HttpContext.Current.Response.StatusCode = strategy.ResponseStatusCode;

                            if (!HttpContext.Current.Request.IsLocal && strategy.ClearException)
                            {
                                HttpContext.Current.Server.ClearError();

                                if (!string.IsNullOrEmpty(strategy.RedirectUrl))
                                {
                                    HttpContext.Current.Response.Redirect(string.Format("{0}/?ID={1}", strategy.RedirectUrl.TrimEnd('/'), info.ID), false);
                                }
                                else
                                {
                                    HttpContext.Current.Response.Write(string.Format(AppInfoCenterConfiguration.GetConfig().ExceptionServiceConfig.UnhandledExceptionMessage, info.ID));
                                    HttpContext.Current.Response.End();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LocalLoggingService.Error("InternalHandle出现错误,异常信息为:" + ex.ToString());
            }
        }
コード例 #2
0
ファイル: ExceptionService.cs プロジェクト: yhhno/Adhesive
 private void LocalLog(ExceptionInfo info, Exception exception, string moduleName, string categoryName, string subcategoryName, string description, ExtraInfo extraInfo)
 {
     var message = new StringBuilder();
     if (info != null)
         message.Append(string.Format("异常类型:{0} ", info.GetType().Name));
     if (!string.IsNullOrEmpty(moduleName))
         message.Append(string.Format("模块名:{0} ", moduleName));
     if (!string.IsNullOrEmpty(categoryName))
         message.Append(string.Format("大类:{0} ", categoryName));
     if (!string.IsNullOrEmpty(subcategoryName))
         message.Append(string.Format("小类:{0} ", subcategoryName));
     if (!string.IsNullOrEmpty(description))
         message.Append(string.Format("描述:{0} ", description));
     if (extraInfo != null)
         message.Append(string.Format("额外信息:{0} ", extraInfo));
     message.Append(string.Format("异常信息:{0} ", exception.ToString()));
     LocalLoggingService.Error(message.ToString());
 }