protected void LogException(Exception ex) { object actionArguments = null, userId = null; HttpContext.Items.TryGetValue("ActionRquestData", out actionArguments); HttpContext.Items.TryGetValue("ControllerName", out object controllerName); HttpContext.Items.TryGetValue("ActionName", out object actionName); LogHandler.Logger _logger = HttpContext.RequestServices.GetService <LogHandler.Logger>(); if (ex is GenericCustomException || ex is NotFoundCustomException || ex is UnauthorizedCustomException) { _logger.WarningLog(ex.Message, actionArguments, errorCode: ErrorCode(ex), identity: Convert.ToString(userId), fileName: $"{controllerName}.cs", methodName: Convert.ToString(actionName)); } else { if (ex.InnerException != null) { if (ex.InnerException.GetType() == typeof(GenericCustomException) || ex.InnerException.GetType() == typeof(NotFoundCustomException) || ex.InnerException.GetType() == typeof(UnauthorizedCustomException)) { _logger.WarningLog(ex.Message, actionArguments, errorCode: ErrorCode(ex), identity: Convert.ToString(userId), fileName: $"{controllerName}.cs", methodName: Convert.ToString(actionName)); } else { _logger.ErrorLog(ex.InnerException.Message, ex, actionArguments, errorCode: ErrorCode(ex), identity: Convert.ToString(userId), fileName: $"{controllerName}.cs", methodName: Convert.ToString(actionName)); } } else { _logger.ErrorLog(ex.Message, ex, actionArguments, errorCode: ErrorCode(ex), identity: Convert.ToString(userId), fileName: $"{controllerName}.cs", methodName: Convert.ToString(actionName)); } } }