From 4d4116788e85fb5a489b57cc4f137775c4426db7 Mon Sep 17 00:00:00 2001 From: Claudia Beatriz Murialdo Garrone Date: Tue, 1 Oct 2024 17:47:18 +0000 Subject: [PATCH] Cherry pick branch 'genexuslabs:improve-trace-error-detail' into beta --- .../GxClasses/Data/GXDataADO.cs | 35 ++++++++++++------- .../GxClasses/Data/GXDataNTier.cs | 21 ++++++----- .../GxClasses/Data/GXDataNTierADO.cs | 12 ++++--- .../GxClasses/Helpers/GXLogging.cs | 12 +++++++ 4 files changed, 54 insertions(+), 26 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs b/dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs index a98288731..0568d8292 100644 --- a/dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs +++ b/dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs @@ -1399,7 +1399,8 @@ public class GxCommand: IGxDbCommand internal List ParmDefinition; static readonly IGXLogger log = GXLoggerFactory.GetLogger(); string stmt; - String stmtId; + string stmtId; + string objName; GxParameterCollection parameters; ushort fetchSize=256; int timeOut; @@ -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) @@ -1593,7 +1595,7 @@ public int ExecuteNonQuery() } catch { } } - GXLogging.Error(log, "Return GxCommand.ExecuteNonQuery Error ", e.Message, e); + GXLogging.Error(log, () => "Return GxCommand.ExecuteNonQuery Error " + e.Message + StmtExceptionDetail, e); try { con.MonitorExit(); @@ -1689,7 +1691,7 @@ private IDataReader ExecRpc() } catch(Exception e) { - GXLogging.Error(log,"Return GxCommand.ExecRpc Error ", e.Message, e); + GXLogging.Error(log,() => "Return GxCommand.ExecRpc Error " + e.Message + StmtExceptionDetail, e); throw (new GxADODataException(e)); } finally @@ -1728,7 +1730,7 @@ public string ExecuteDataSet() } catch(Exception e) { - GXLogging.Error(log, "Return GxCommand.ExecuteDataSet Error ", e.Message, e); + GXLogging.Error(log, () => "Return GxCommand.ExecuteDataSet Error " + e.Message + StmtExceptionDetail, e); throw (new GxADODataException(e)); } } @@ -1738,7 +1740,7 @@ public string ExecuteDataSet() retryCount++; if (! pe) { - GXLogging.Error(log, "GxCommand.ExecuteDataSet Error ", e.Message, e); + GXLogging.Error(log, () => "GxCommand.ExecuteDataSet Error " + e.Message + StmtExceptionDetail, e); throw; } } @@ -1805,7 +1807,7 @@ public IDataReader ExecuteReader() } catch (Exception e) { - GXLogging.Error(log, "Return GxCommand.ExecuteReader Error ", e.Message, e); + GXLogging.Error(log, () => "Return GxCommand.ExecuteReader Error " + e.Message + StmtExceptionDetail, e); if (e.InnerException != null) { GXLogging.Error(log, "Inner Error", e.InnerException); @@ -1814,6 +1816,13 @@ public IDataReader ExecuteReader() } } + private string StmtExceptionDetail + { + get + { + return "\nObjectName:" + objName + "\nStmt:" + stmt; + } + } public void FetchData(out IDataReader dr) { @@ -1839,7 +1848,7 @@ public void FetchData(out IDataReader dr) retryCount++; if (! pe) { - GXLogging.Error(log, "GxCommand.FetchData Error ", e.Message, e); + GXLogging.Error(log, () => "GxCommand.FetchData Error " + e.Message + StmtExceptionDetail, e); throw; } } @@ -1866,7 +1875,7 @@ public void FetchDataRPC(out IDataReader dr) retryCount++; if (! pe) { - GXLogging.Error(log, "GxCommand.FetchDataRPC Error ", e.Message, e); + GXLogging.Error(log, () => "GxCommand.FetchDataRPC Error " + e.Message + StmtExceptionDetail, e); throw; } } @@ -1923,7 +1932,7 @@ public int ExecuteBatchQuery() } catch (Exception e) { - GXLogging.Error(log, "Return GxCommand.ExecuteNonQuery Error ", e.Message, e); + GXLogging.Error(log, ()=>"Return GxCommand.ExecuteNonQuery Error " + e.Message + StmtExceptionDetail, e); con.InternalConnection.RollbackSavePoint(Transaction, stmtId); con.MonitorExit(); throw (new GxADODataException(e)); @@ -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.Message, e); + if (!pe) + { + GXLogging.Error(log, () => "GxCommand.ExecuteStmt Error " + e.Message + StmtExceptionDetail, e); throw; } } @@ -2017,7 +2026,7 @@ private void execStmt() retryCount++; if (!pe) { - GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e.Message, e); + GXLogging.Error(log, ()=> "GxCommand.ExecuteStmt Error " + e.Message + StmtExceptionDetail, e); throw; } } diff --git a/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs b/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs index 49b7b55f5..5b22c2db2 100644 --- a/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs +++ b/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs @@ -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(); @@ -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 DynamicParameters { get; } } @@ -352,6 +353,7 @@ public class DataStoreProvider : IDataStoreProviderBase,IDataStoreProvider IDictionary errorBuffers; IGxDataStore _ds; IDataStoreHelper _dataStoreHelper; + string _dataStoreHelperType; object [] _dynConstraints; GxErrorHandler _errorHandler; IGxContext _context; @@ -362,16 +364,17 @@ 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(); @@ -379,7 +382,7 @@ public DataStoreProvider( IGxContext context, IDataStoreHelper dataStoreHelper, errorBuffers = new Dictionary(); if (Preferences.Instrumented) { - wmiDataStoreProvider = WMIDataStoreProviders.Instance().AddDataStoreProvider(dataStoreHelper.GetType().ToString()); + wmiDataStoreProvider = WMIDataStoreProviders.Instance().AddDataStoreProvider(_dataStoreHelperType); } dataStoreRequestCount++; @@ -423,8 +426,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) { @@ -682,7 +685,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); } } diff --git a/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs b/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs index dca7a3d7f..edc05636b 100644 --- a/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs +++ b/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs @@ -864,8 +864,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) @@ -874,7 +873,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); @@ -886,7 +885,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) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs index a6e532a4a..571e7a773 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs @@ -625,6 +625,18 @@ internal static void ErrorSanitized(IGXLogger logger, string msg, Exception ex) } } } + internal static void Error(IGXLogger logger, Func buildMsg, Exception ex) + { + if (logger != null) + { + if (logger.IsErrorEnabled) + { + string msg = buildMsg(); + logger.LogError(msg, ex); + } + } + } + internal static void Error(IGXLogger logger, string msg1, string msg2, Exception ex) {