Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Error log to include exception message on the same line. #1063

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected GxConnectionManager()
}
catch(Exception e){

GXLogging.Error(log, "Error setting CONN_TIMEOUT ", e);
GXLogging.Error(log, "Error setting CONN_TIMEOUT ", e.Message, e);
}
}

Expand Down Expand Up @@ -209,7 +209,7 @@ public void RemoveAllConnections(int handle)
}
catch(Exception e)
{
GXLogging.Error(log, "RemoveAllConnections Error", e);
GXLogging.Error(log, "RemoveAllConnections Error", e.Message,e);
throw e;
}
}
Expand Down Expand Up @@ -526,7 +526,7 @@ public void Open()
}
catch (Exception ex)
{
GXLogging.Error(log, "GxConnection.Open Error ", ex);
GXLogging.Error(log, "GxConnection.Open Error ", ex.Message, ex);
lastErrorCode = 3;
lastErrorMsg = "Internal error: Function call failed (" + ex.Message + ")";
throw ex;
Expand All @@ -548,7 +548,7 @@ public void Open()
int status=0;
if (!m_dataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, GxErrorMask.GX_NOMASK, this, ref status, ref retry, 0))
{
GXLogging.Error(log, "GxConnection.Open Error ",e);
GXLogging.Error(log, "GxConnection.Open Error ", e.Message, e);
lastErrorCode = 3;
lastErrorMsg = "Internal error: Function call failed ("+ e.ErrorInfo + ")";
throw e;
Expand Down Expand Up @@ -700,7 +700,7 @@ public short FullConnect()
}
catch(Exception ex)
{
GXLogging.Error(log, "FullConnect Error " + databaseName, ex);
GXLogging.Error(log, "FullConnect Error " + databaseName, ex.Message, ex);
return 1;
}
}
Expand Down Expand Up @@ -1399,7 +1399,8 @@ public class GxCommand: IGxDbCommand
internal List<ParDef> ParmDefinition;
static readonly IGXLogger log = GXLoggerFactory.GetLogger<GxCommand>();
string stmt;
String stmtId;
string stmtId;
string objName;
GxParameterCollection parameters;
ushort fetchSize=256;
int timeOut;
Expand Down Expand Up @@ -1466,7 +1467,7 @@ public GxCommand( IGxDataRecord db, String statement, IGxDataStore ds, int ttl,
bool retry=false;
if (! dataRecord.ProcessError( e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, 0))
{
GXLogging.Error(log, "Return Error GxCommand ", e);
GXLogging.Error(log, "Return Error GxCommand ", e.Message, e);
throw (new GxADODataException(e.ErrorInfo, e));
}
}
Expand All @@ -1484,6 +1485,7 @@ public GxCommand( IGxDataRecord db, String statement, short updatable,
IGxDataStore ds, string objName, string stmtId, int ttl, bool hasNested,bool isForFirst, GxErrorHandler errorHandler):this(db, statement,ds, ttl,hasNested, isForFirst, errorHandler)
{
this.stmtId = stmtId;
this.objName = objName;
}
public GxCommand(IGxDataRecord db, String statement, short updatable,
IGxDataStore ds, string objName, string stmtId, int ttl, bool hasNested, bool isForFirst, GxErrorHandler errorHandler, int batchSize)
Expand Down Expand Up @@ -1593,7 +1595,7 @@ public int ExecuteNonQuery()
}
catch { }
}
GXLogging.Error(log, e, "Return GxCommand.ExecuteNonQuery Error ");
GXLogging.Error(log, () => "Return GxCommand.ExecuteNonQuery Error " + e.Message + StmtExceptionDetail, e);
try
{
con.MonitorExit();
Expand Down Expand Up @@ -1689,7 +1691,7 @@ private IDataReader ExecRpc()
}
catch(Exception e)
{
GXLogging.Error(log, e, "Return GxCommand.ExecRpc Error ");
GXLogging.Error(log,() => "Return GxCommand.ExecRpc Error " + e.Message + StmtExceptionDetail, e);
throw (new GxADODataException(e));
}
finally
Expand Down Expand Up @@ -1728,7 +1730,7 @@ public string ExecuteDataSet()
}
catch(Exception e)
{
GXLogging.Error(log, e, "Return GxCommand.ExecuteDataSet Error ");
GXLogging.Error(log, () => "Return GxCommand.ExecuteDataSet Error " + e.Message + StmtExceptionDetail, e);
throw (new GxADODataException(e));
}
}
Expand All @@ -1738,7 +1740,7 @@ public string ExecuteDataSet()
retryCount++;
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.ExecuteDataSet Error ");
GXLogging.Error(log, () => "GxCommand.ExecuteDataSet Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down Expand Up @@ -1805,7 +1807,7 @@ public IDataReader ExecuteReader()
}
catch (Exception e)
{
GXLogging.Error(log, "Return GxCommand.ExecuteReader Error ", e);
GXLogging.Error(log, () => "Return GxCommand.ExecuteReader Error " + e.Message + StmtExceptionDetail, e);
if (e.InnerException != null)
{
GXLogging.Error(log, "Inner Error", e.InnerException);
Expand All @@ -1814,6 +1816,13 @@ public IDataReader ExecuteReader()
}

}
private string StmtExceptionDetail
{
get
{
return "\nObjectName:" + objName + "\nStmt:" + stmt;
}
}

public void FetchData(out IDataReader dr)
{
Expand All @@ -1839,7 +1848,7 @@ public void FetchData(out IDataReader dr)
retryCount++;
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.FetchData Error ");
GXLogging.Error(log, () => "GxCommand.FetchData Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand All @@ -1866,7 +1875,7 @@ public void FetchDataRPC(out IDataReader dr)
retryCount++;
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.FetchDataRPC Error ");
GXLogging.Error(log, () => "GxCommand.FetchDataRPC Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down Expand Up @@ -1923,7 +1932,7 @@ public int ExecuteBatchQuery()
}
catch (Exception e)
{
GXLogging.Error(log, "Return GxCommand.ExecuteNonQuery Error ", e);
GXLogging.Error(log, ()=>"Return GxCommand.ExecuteNonQuery Error " + e.Message + StmtExceptionDetail, e);
con.InternalConnection.RollbackSavePoint(Transaction, stmtId);
con.MonitorExit();
throw (new GxADODataException(e));
Expand Down Expand Up @@ -1986,9 +1995,9 @@ public void ExecuteBatch()
{
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e);
if (!pe)
{
GXLogging.Error(log, () => "GxCommand.ExecuteStmt Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down Expand Up @@ -2017,7 +2026,7 @@ private void execStmt()
retryCount++;
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e);
GXLogging.Error(log, ()=> "GxCommand.ExecuteStmt Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down Expand Up @@ -2599,7 +2608,7 @@ private void Initialize(IGxDataRecord db, string id, int hnd, IGxContext context
}
catch (Exception ex)
{
GXLogging.Error(log, "Error creating CustomDataRecord " + providerService.ClassName, ex);
GXLogging.Error(log, "Error creating CustomDataRecord " + providerService.ClassName, ex.Message, ex);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public virtual IDbCommand GetCommand(IGxConnection con, string stmt, GxParameter
}
catch (Exception ex)
{
GXLogging.Error(log, "Set Binary parameter length in cached command error", ex);
GXLogging.Error(log, "Set Binary parameter length in cached command error", ex.Message, ex);
}
}
}
Expand Down Expand Up @@ -1963,7 +1963,7 @@ public override void GetValues(IDataReader reader, ref object[] values)
}
catch (Exception ex)
{
GXLogging.Error(log, "GetValues error", ex);
GXLogging.Error(log, "GetValues error", ex.Message, ex);
}
}
static internal decimal ReadSQLDecimal(SqlDataReader sqlReader, int idx) {
Expand Down Expand Up @@ -2261,7 +2261,7 @@ public bool Read()
}
catch (Exception ex)
{
GXLogging.Error(log, "ReadError", ex);
GXLogging.Error(log, "ReadError", ex.Message, ex);
throw (new GxADODataException(ex));
}
}
Expand Down Expand Up @@ -3162,7 +3162,7 @@ public void unprepare(int cursorId )
}
catch (Exception e)
{
GXLogging.Error(log, "GxCommand.unprepare Error ", e);
GXLogging.Error(log, "GxCommand.unprepare Error ", e.Message, e);
}
}
public void UnprepareClear()
Expand Down Expand Up @@ -3324,7 +3324,7 @@ public void LoadBlock()
{
if (reader != null) reader.Close();
GXLogging.Error(log, "stmt:" + this.stmt);
GXLogging.Error(log, "LoadBlock error ", e);
GXLogging.Error(log, "LoadBlock error ", e.Message, e);

Dispose();
hasnext = false;
Expand Down
33 changes: 18 additions & 15 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public interface IRemoteDataStoreProvider

public interface ICursor
{
void createCursor( IGxDataStore ds, GxErrorHandler errorHandler );
void createCursor( IGxDataStore ds, GxErrorHandler errorHandler);
void createCursor(IGxDataStore ds, GxErrorHandler errorHandler, string objName);
void execute();
short[] preExecute(int cursorNum, IDataStoreProviderBase connectionProvider, IGxDataStore ds);
void readNext();
Expand All @@ -67,7 +68,7 @@ public interface ICursor
void addRecord(Object[] parms);
int BatchSize { get; set;}
int RecordCount { get;}
void OnCommitEvent(object instance, string method);
void OnCommitEvent(object instance, string method);
int readNextErrorRecord();
List<ParDef> DynamicParameters { get; }
}
Expand Down Expand Up @@ -349,6 +350,7 @@ public class DataStoreProvider : IDataStoreProviderBase,IDataStoreProvider
IDictionary<int, Object[]> errorBuffers;
IGxDataStore _ds;
IDataStoreHelper _dataStoreHelper;
string _dataStoreHelperType;
object [] _dynConstraints;
GxErrorHandler _errorHandler;
IGxContext _context;
Expand All @@ -359,24 +361,25 @@ public class DataStoreProvider : IDataStoreProviderBase,IDataStoreProvider

public DataStoreProvider( IGxContext context, IDataStoreHelper dataStoreHelper, Object[][] cursorParms)
{
GXLogging.Debug(log, "Start DataStoreProvider.Ctr, Parameters: handle '"+ context.handle + "', dataStoreHelper:" + dataStoreHelper.GetType());
_dataStoreHelperType = dataStoreHelper.GetType().ToString();
GXLogging.Debug(log, "Start DataStoreProvider.Ctr, Parameters: handle '"+ context.handle + "', dataStoreHelper:" + _dataStoreHelperType);
_dataStoreHelper = dataStoreHelper;
_context = context;
_context = context;
_ds = context.GetDataStore( dataStoreHelper.getDataStoreName());
if (_ds == null)
{

_ds = new GxDataStore(new GxSqlServer(),dataStoreHelper.getDataStoreName(), context);
context.AddDataStore(_ds);
GXLogging.Error(log, dataStoreHelper.GetType() + " Datastore " + dataStoreHelper.getDataStoreName() + " not found in app config");
GXLogging.Error(log, _dataStoreHelperType + " Datastore " + dataStoreHelper.getDataStoreName() + " not found in app config");
}
_ds.Handle=context.handle;
_cursor = dataStoreHelper.getCursors();
results = cursorParms;
errorBuffers = new Dictionary<int, Object[]>();
if (Preferences.Instrumented)
{
wmiDataStoreProvider = WMIDataStoreProviders.Instance().AddDataStoreProvider(dataStoreHelper.GetType().ToString());
wmiDataStoreProvider = WMIDataStoreProviders.Instance().AddDataStoreProvider(_dataStoreHelperType);
}
dataStoreRequestCount++;

Expand Down Expand Up @@ -420,8 +423,8 @@ private void execute(int cursor, Object[] parms, bool batch)
}
if (!batch)
{
oCur.createCursor(_ds, _errorHandler);
}
oCur.createCursor(_ds, _errorHandler, _dataStoreHelperType);
}
short[] parmHasValue = oCur.preExecute(cursor, this, _ds);
if (Preferences.Instrumented && wmiDataStoreProvider != null)
{
Expand Down Expand Up @@ -476,7 +479,7 @@ private void execute(int cursor, Object[] parms, bool batch)
}
catch (Exception ex)
{
GXLogging.Error(log, "Execute error", ex);
GXLogging.Error(log, "Execute error", ex.Message, ex);
_ds.CloseConnections();
throw ex;
}
Expand Down Expand Up @@ -520,7 +523,7 @@ public void readNext(int cursor)
if (oCur != null)
{
bool pe = oCur.Command.ProcessException(e, ref retry, retryCount, "FETCH");
GXLogging.Error(log, "readNext Error", e);
GXLogging.Error(log, "readNext Error", e.Message, e);
if (!pe)
{
throw;
Expand Down Expand Up @@ -579,7 +582,7 @@ private void commitDataStore(IGxDataStore ds, String auditObjectName)
GxADODataException e = new GxADODataException(dbEx);
bool retry = false;
int retryCount = 0;
GXLogging.Error(log, "Commit Transaction Error", e);
GXLogging.Error(log, "Commit Transaction Error", e.Message, e);
bool pe = cmd.ProcessException(e, ref retry, retryCount, "FETCH");
if (!pe)
{
Expand All @@ -590,7 +593,7 @@ private void commitDataStore(IGxDataStore ds, String auditObjectName)
}
catch (Exception ex)
{
GXLogging.Error(log, "beginTransaction in commit transaction failed", ex);
GXLogging.Error(log, "beginTransaction in commit transaction failed",ex.Message, ex);
throw (new GxADODataException(e.ToString(), e));
}
}
Expand All @@ -612,7 +615,7 @@ private void rollbackDataStore(IGxDataStore ds, String auditObjectName)
bool retry = false;
int retryCount = 0;
bool pe = cmd.ProcessException(e, ref retry, retryCount, "FETCH");
GXLogging.Error(log, "Rollback Transaction Error", e);
GXLogging.Error(log, "Rollback Transaction Error", e.Message, e);
if (!pe)
{
try
Expand All @@ -622,7 +625,7 @@ private void rollbackDataStore(IGxDataStore ds, String auditObjectName)
}
catch (Exception ex)
{
GXLogging.Error(log, "beginTransaction in Rollback transaction failed", ex);
GXLogging.Error(log, "beginTransaction in Rollback transaction failed", ex.Message, ex);
throw (new GxADODataException(e.ToString(), e));
}
}
Expand Down Expand Up @@ -679,7 +682,7 @@ public void initializeBatch(int cursor, int batchSize, object instance, string m
if (oCur.BatchSize == 0)
{
oCur.BatchSize = batchSize;
oCur.createCursor(_ds, _errorHandler);
oCur.createCursor(_ds, _errorHandler, _dataStoreHelperType);
oCur.OnCommitEvent(instance, method);
}
}
Expand Down
12 changes: 8 additions & 4 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,7 @@ internal GxCommand Command
{
get { return _gxDbCommand; }
}

public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler, string objectName)
{

if (_state >= 2)
Expand All @@ -859,7 +858,7 @@ public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
return;
}
_stmt = (_staticParameters == null)? _stmt : String.Format(_stmt, _staticParameters);
_gxDbCommand = new GxCommand(ds.Db, _stmt, _updatable, ds, "", _name, TTL, hasNested, isForFirst, errorHandler, _batchSize);
_gxDbCommand = new GxCommand(ds.Db, _stmt, _updatable, ds, objectName, _name, TTL, hasNested, isForFirst, errorHandler, _batchSize);
_gxDbCommand.IsCursor = true;
if (_blockSize > 0)
_gxDbCommand.FetchSize = Convert.ToUInt16(_blockSize);
Expand All @@ -871,7 +870,12 @@ public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
_gxDbCommand.ErrorMask = _errMask;

}
protected virtual void bindParms(Object[] ptb)
public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
{
createCursor(ds, errorHandler, string.Empty);
}

protected virtual void bindParms(Object[] ptb)
{
int pos = 1;
if (ptb != null)
Expand Down
Loading
Loading