public async Task <IActionResult> Index() { IExceptionHandlerPathFeature handler = HttpContext .Features.Get <IExceptionHandlerPathFeature>(); string message = "متاسفیم که عملیات با مشکل مواجه شده. بهتره به خانه برگردین! :)"; if (handler != null) { string requestPath = handler.Path; Exception exception = handler.Error; var errorData = new CreateErrorLogDto { Exception = exception, StatusCode = 0, RequestUrl = requestPath }; try { //If database is not availabe, we must catch exception and log error in a diffrent storage await _errorLogService.CreateAsync(errorData); } catch (Exception ex) { //Log error in another storage, //instead of Database, because database is not available. Console.WriteLine($"Fatal-Error: {ex.GetBaseException().Message}"); return(await Task.FromResult( View(new ErrorViewModel { Message = message, Help = ex.GetBaseException().Message, ReturnUrl = _ReturnUrl }) )); } var routeVlaues = new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" } }; var model = new ErrorViewModel { Message = message, ReturnUrl = _ReturnUrl }; return(await Task.FromResult(View(model))); } return(await Task.FromResult(View())); }
public async Task <ErrorLog> MakeAsync(CreateErrorLogDto model) { model.CheckArgumentIsNull(nameof(model)); var result = model.Adapt <ErrorLog>(); result.WebsiteId = _websiteInfo.Id; result.Ip = AppHttpContext.Current .Connection .RemoteIpAddress?.ToString(); result.UserAgent = AppHttpContext.Request.Headers["User-Agent"][0]; result.SessionId = AppHttpContext.Current.Session.Id; result.CreateDate = _dateService.UtcNow(); result.Exception = model.Exception.GetBaseException().Message; result.StackTrace = model.Exception.GetBaseException() .StackTrace .Substring(0, 3000); return(await Task.FromResult(result)); }
public async Task CreateAsync(CreateErrorLogDto model) { var entity = await _factory.MakeAsync(model); await _repository.AddAndSaveAsync(entity); }