public ActionResult Create([Bind(Include = "EventLog, Number, Message, StackTrace")] EventLogError eventLogError)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    EventLogErrorServices.Insert(CurrentUser.Id, eventLogError, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed");
                    return(RedirectToAction("Index"));
                }
                catch (CfException cfex)
                {
                    TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                }
                catch (Exception ex)
                {
                    TempData["Failure"] = ex.Message;
                }
            }

            ViewBag.EventLogList = new SelectList(EventLogServices.List(db), "Id", "Name");
            return(View(eventLogError));
        }
Beispiel #2
0
        //     internal static CfException LogError(EventLog eventLog, CfException ex, Db db)
        //     {
        //string trace = Environment.StackTrace;
        //         if (ex.StackTrace != null)
        //             trace = ex.StackTrace;
        //         else if (ex.InnerException != null && ex.InnerException.StackTrace != null)
        //             trace = ex.InnerException.StackTrace;
        //         EventLogError error = new EventLogError();
        //         error.EventLog = eventLog.Id;
        //         error.Number = ex.Number;
        //         error.Message = ex.Message;
        //         error.StackTrace = trace;
        //         EventLogErrorServices.Insert(error, db);

        //ErrorDefinition errorDefinition = new ErrorDefinition();
        //errorDefinition.Message = ex.Message;
        //errorDefinition.LocalizedMessage = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UnexpectedError"); ;
        //errorDefinition.LikeExpression = ex.Message;
        //errorDefinition = ErrorDefinitionServices.Insert(errorDefinition, db);
        //ex.ErrorDefinition = errorDefinition;
        //     }

        internal static CfException LogError(EventLog eventLog, Exception ex, string module, Db db)
        {
            CfException exception = new CfException(module, eventLog.EventCategory, ex.Message, ex);
            string      trace     = Environment.StackTrace;

            if (exception.StackTrace != null)
            {
                trace = exception.StackTrace;
            }
            else if (exception.InnerException != null && exception.InnerException.StackTrace != null)
            {
                trace = exception.InnerException.StackTrace;
            }
            EventLogError error = new EventLogError();

            error.EventLog   = eventLog.Id;
            error.Number     = exception.Number;
            error.Message    = exception.Message;
            error.StackTrace = trace;
            EventLogErrorServices.Insert(error, db);

            ErrorDefinition errorDefinition = new ErrorDefinition();

            errorDefinition.Message          = exception.Message;
            errorDefinition.LocalizedMessage = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UnexpectedError");
            errorDefinition.LikeExpression   = exception.Message;
            errorDefinition           = ErrorDefinitionServices.Insert(errorDefinition, db);
            exception.ErrorDefinition = errorDefinition;

            return(exception);
        }