OK, You did ask…
Here is the code in the function(s)…
BO Update:
Exception exceptionObject = JsonConvert.DeserializeObject<Exception>(exception);
Dictionary<string, object> objectsToSave = new Dictionary<string, object>();
objectsToSave.Add("Exception", exceptionObject);
CallService<UD20SvcContract>(boUD20 =>
{
UD20Tableset ud20Tableset = new UD20Tableset();
DateTime now = DateTime.Now;
TimeSpan timeAfterMidnight = DateTime.Now - DateTime.Today;
UD20Row logRow = new UD20Row()
{
Key1 = Guid.NewGuid().ToString(),
Key2 = project,
Key3 = "Error",
Key4 = "Exception",
Character01 = exceptionObject.Message,
Character02 = exceptionObject.InnerException == null ? "" : exceptionObject.InnerException.Message,
Date01 = DateTime.Today,
Number01 = Convert.ToInt64(timeAfterMidnight.TotalSeconds),
ShortChar01 = callContextClient.CurrentUserId,
ShortChar02 = action,
Character03 = actionData1,
Character04 = actionData2,
Character05 = notes,
Character06 = JsonConvert.SerializeObject(objectsToSave),
RowMod = "A",
SysRevID = now.Ticks
};
ud20Tableset.UD20.Add(logRow);
boUD20.Update(ref ud20Tableset);
});
Direct Update:
Exception exceptionObject = JsonConvert.DeserializeObject<Exception>(exception);
Dictionary<string, object> objectsToSave = new Dictionary<string, object>();
objectsToSave.Add("Exception", exceptionObject);
DateTime now = DateTime.Now;
TimeSpan timeAfterMidnight = DateTime.Now - DateTime.Today;
UD20 logRow = new UD20()
{
Key1 = Guid.NewGuid().ToString(),
Key2 = project,
Key3 = "Error",
Key4 = "Exception",
Character01 = exceptionObject.Message,
Character02 = exceptionObject.InnerException == null ? "" : exceptionObject.InnerException.Message,
Date01 = DateTime.Today,
Number01 = Convert.ToInt64(timeAfterMidnight.TotalSeconds),
ShortChar01 = callContextClient.CurrentUserId,
ShortChar02 = action,
Character03 = actionData1,
Character04 = actionData2,
Character05 = notes,
Character06 = JsonConvert.SerializeObject(objectsToSave),
SysRevID = BitConverter.GetBytes(now.Ticks)
};
Db.AddObject(logRow);
Db.SaveChanges();
The Test Harness:
System.Diagnostics.Stopwatch stopwatch1 = new System.Diagnostics.Stopwatch();
System.Diagnostics.Stopwatch stopwatch2 = new System.Diagnostics.Stopwatch();
stopwatch1.Start();
int recCount = 10000;
for(int cnt = 0; cnt < recCount; cnt++)
{
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception ex)
{
InvokeFunction("KEVUTILITY", "LogException", "LoggingTest", "Test_Exception", "", "", "", JsonConvert.SerializeObject(ex));
}
}
stopwatch1.Stop();
stopwatch2.Start();
for(int cnt = 0; cnt < recCount; cnt++)
{
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception ex)
{
InvokeFunction("KEVUTILITY", "LogException2", "LoggingTest", "Test_Exception", "", "", "", JsonConvert.SerializeObject(ex));
}
}
stopwatch2.Stop();
InfoMessage.Publish($"BO Update: {stopwatch1.Elapsed.TotalSeconds.ToString()} seconds\nDirect Update: {stopwatch2.Elapsed.TotalSeconds.ToString()} seconds");
And the Results:
1000 Records
Run 1 (1000) Records
BO Update: 5.4984802 seconds
Direct Update: 2.4482677 seconds
Run 2 (1000) Records
BO Update: 4.8526954 seconds
Direct Update: 2.3025349 seconds
Run 3 (1000) Records
BO Update: 4.9567663 seconds
Direct Update: 2.3572281 seconds
10,000 Records
Run 1 (10000) Records
BO Update: 50.6735952 seconds
Direct Update: 24.6151174 seconds
Run 2 (10000) Records
BO Update: 50.8568047 seconds
Direct Update: 25.8428644 seconds
Run 3 (10000) Records
BO Update: 50.2500386 seconds
Direct Update: 23.5107262 seconds
Conclusion: If it get’s called enough it’s worth it. Direct Update is roughly half the time of the BO.