예제 #1
0
        void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            //TODO read in xml log files
            //Elmah.XmlFileErrorLog log = new XmlFileErrorLog("~/ElmahLog");

            ElmahError err = new ElmahError();


            //using (var context = new ElmahContext())
            //{
            //    //if the exception had the same message and was from
            //    //the last 10 min it means it's the same we dismiss it
            //    _sendEmail = true;
            //    var lastErr = context.ELMAH_Errors
            //    .OrderByDescending(m => m.TimeUtc).Take(1)
            //    .SingleOrDefault();
            //    if (lastErr != null &&
            //    (e.Exception.Message == lastErr.Message &&
            //    lastErr.TimeUtc > DateTime.UtcNow.AddMinutes(-10)))
            //    {
            //        e.Dismiss();
            //        _sendEmail = false;
            //    }
            //}

            if (e.Exception.GetBaseException() is HttpRequestValidationException)
            {
                e.Dismiss();
            }
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("ErrorId,Application,Host,Type,Source,Message,User,StatusCode,TimeUtc,Sequence,AllXml")] ElmahError elmahError)
        {
            if (id != elmahError.ErrorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(elmahError);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ElmahErrorExists(elmahError.ErrorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(elmahError));
        }
        public async Task <IActionResult> Create([Bind("ErrorId,Application,Host,Type,Source,Message,User,StatusCode,TimeUtc,Sequence,AllXml")] ElmahError elmahError)
        {
            if (ModelState.IsValid)
            {
                elmahError.ErrorId = Guid.NewGuid();
                _context.Add(elmahError);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(elmahError));
        }
예제 #4
0
        public async Task <ActionResult> ErrorLogDetail(Guid id)
        {
            ElmahError          elmah   = new ElmahError();
            string              token   = Session["UserToken"].ToString();
            string              address = "api/Elmah/GetElmahErrorById/" + id.ToString();
            HttpResponseMessage Res     = await Helpers.Get(address, token);

            if (Res.IsSuccessStatusCode)
            {
                var MainMEnuResponse = Res.Content.ReadAsStringAsync().Result;
                elmah = JsonConvert.DeserializeObject <ElmahError>(MainMEnuResponse);
            }
            return(PartialView(elmah));
        }
예제 #5
0
        public ErrorLogEntry ToError(ElmahError elmahError)
        {
            Contract.Requires(elmahError != null);

            var error = new Error
            {
                ApplicationName = elmahError.ApplicationName,
                HostName        = elmahError.Host,
                Type            = elmahError.Type,
                Source          = elmahError.Source,
                Message         = elmahError.Message,
                Detail          = elmahError.Detail,
                User            = elmahError.User,
                Time            = elmahError.TimeUtc,
                StatusCode      = elmahError.StatusCode,
            };

            return(new ErrorLogEntry(this, elmahError.DateTimeId, error));
        }
예제 #6
0
        protected virtual ElmahError MaterializeElmahError(IDataReader reader, bool includeDetails, int rowNum)
        {
            var instance = new ElmahError();

            instance.ErrorId     = reader.GetGuid(0);
            instance.Application = reader.GetString(1);
            instance.Host        = reader.GetString(2);
            instance.Type        = reader.GetString(3);
            instance.Source      = reader.GetString(4);
            instance.Message     = reader.GetString(5);
            instance.User        = reader.GetString(6);
            instance.StatusCode  = reader.GetInt32(7);
            instance.TimeUtc     = DateTime.SpecifyKind(reader.GetDateTime(8), DateTimeKind.Utc);
            instance.Sequence    = reader.GetInt32(9);
            instance.RowNum      = rowNum;
            if (includeDetails)
            {
                instance.AllXml = System.Xml.Linq.XDocument.Parse(reader.GetString(10));
            }
            return(instance);
        }
예제 #7
0
        /// <summary>
        /// Log an error to Elmah
        /// </summary>
        /// <param name="error"> Error can be obtained from filtercontext</param>
        /// <returns> DatetimeID will be returned if it's log sucessfully committed</returns>
        public override string Log(Error error)
        {
            var elmahError = new ElmahError
            {
                DateTimeId      = ToDateTimeId(error.Time),
                ApplicationName = _applicationName,
                Host            = error.HostName,
                Type            = error.Type,
                Source          = error.Source,
                Message         = error.Message,
                Detail          = error.Detail,
                User            = error.User,
                StatusCode      = error.StatusCode,
                TimeUtc         = error.Time.ToUniversalTime(),
                Form            = ToDictionary(error.Form),
                ServerVariables = ToDictionary(error.ServerVariables),
                Cookies         = ToDictionary(error.Cookies),
                QueryString     = ToDictionary(error.QueryString)
            };

            _repository.Add(elmahError);

            return(elmahError.DateTimeId);
        }
예제 #8
0
 public ElmahErrorViewModel(ElmahError instance)
 {
     this.Instance = instance;
 }
예제 #9
0
 public static void ElmahErrorCapture(ElmahError elmahError)
 {
 }