[Route("API/Add")]
[HttpPost]
public GenericClasss AddData(CAddData_Request Data)
{
GenericClasss Obj = new GenericClasss();
try
{
Obj = _Base.AddDataa(Data);
}
catch (System.Exception ex)
{
string JsonData = _Base.ConvertJsontoString(Data);
_Base.ServiceLogException(ex, ActionContext.ActionDescriptor.ActionName, JsonData);
}
return Obj;
}
}
public void ServiceLogException(System.Exception ex, string MethodName, string Data)
{
try
{
AppException _Exception = new AppException();
_Exception.Employee_ID = null;
_Exception.Method = MethodName;
_Exception.Page = "";
_Exception.Line = ex == null ? "0" : Convert.ToString(new System.Diagnostics.StackTrace(ex, true).GetFrame(0).GetFileLineNumber());
_Exception.Object = Data;
_Exception.Message = ex == null ? null : ex.Message;
_Exception.CreatedDate = System.DateTime.UtcNow;
_Exception.ExceptionType = 2;
_Exception.IsSolved = false;
DB.AppExceptions.Add(_Exception);
DB.SaveChanges();
}
catch (Exception exa)
{
}
}
问题:
如果AddData
方法生成异常
插入语句与外键约束冲突
然后将其转到catch块并将异常条目插入数据库中。
但是我的ServiceLogException
方法也会生成相同的异常
插入语句与外键约束冲突