public static void logErrors(myStatusCodeHandling _statusProblem = null, object _exceptionHandlerPathFeature = null, HttpResponse _response = null) { using (MVCContext myContext = new MVCContext()) { TblErrorLogs errorObj = new TblErrorLogs(); if (_exceptionHandlerPathFeature != null) { var exceptionHandlerPathFeature = (IExceptionHandlerPathFeature)_exceptionHandlerPathFeature; errorObj.ExMsg = exceptionHandlerPathFeature.Error?.Message; errorObj.ExStackTrace = exceptionHandlerPathFeature.Error?.StackTrace; errorObj.ExPath = exceptionHandlerPathFeature?.Path; errorObj.InnerExMsg = exceptionHandlerPathFeature.Error?.InnerException?.Message; errorObj.InnerExStackTrace = exceptionHandlerPathFeature.Error?.InnerException?.StackTrace; } if (_response != null) { errorObj.HttpErrorStatusCode = (short)_response?.StatusCode; errorObj.HttpErrorCookies = _response?.Cookies.ToString(); errorObj.HttpErrorPath = _response?.HttpContext?.Request?.Path; errorObj.HttpErrorRequest = _response?.HttpContext?.Request?.ToString(); } if (_statusProblem != null) { errorObj.HttpErrorStatusCode = (short)_statusProblem.irStatusCode; errorObj.HttpErrorPath = _statusProblem.OriginalPath; errorObj.HttpErrorRequest = _statusProblem.OriginalPathBase; errorObj.HttpErrorCookies = _statusProblem.OriginalQueryString; } myContext.TblErrorLogs.Add(errorObj); myContext.SaveChanges(); } }
public IActionResult Error404(int?irErrorCode = null) { var feature = HttpContext.Features.Get <IStatusCodeReExecuteFeature>(); myStatusCodeHandling myHandler = new myStatusCodeHandling(feature, irErrorCode); GlobalMethods.logErrors(_statusProblem: myHandler); return(View("/Views/Error404.cshtml")); }