0
bluescopesteel created
- What is your product version? - 10.04
- What is your product type (Angular or MVC)? - Angular
- What is product framework type (.net framework or .net core)? - .net core
Hi Support team,
Whenever an error occurs in our code, we are adding it into the database table - Alerts.
For Eg: our helper class function is:
public async Task InsertAlert(int tenantId, int orderId, int source, int severity, string message)
{
Alert alert = new Alert() { TenantId = tenantId, OrderId = orderId, Source = source,
Severity = severity, Message = message};
await _alertRepository.InsertAsync(alert).ConfigureAwait(true);
CurrentUnitOfWork.SaveChanges();
}
This is working fine for normal errors, however when exceptions are thrown, Alert will not be saved to DB. We would like to save this entry to Alert table.
Then I have modified the function as shown below to handle both Exception and non-Exception case, but I am not sure it is the best way..
public async Task InsertAlert(int tenantId, int orderId, int source, int severity, string message, bool isThrowingException)
{
Alert alert = new Alert() {TenantId = tenantId, OrderId = orderId, Source = source, Severity = severity, Message = message};
if (isThrowingException)
{
using (var unitOfWork = UnitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
{
await _alertRepository.InsertAsync(alert).ConfigureAwait(true);
unitOfWork.Complete();
}
}
{
using (var unitOfWork = UnitOfWorkManager.Begin())
{
await _alertRepository.InsertAsync(alert).ConfigureAwait(true);
unitOfWork.Complete();
}
}
}
Please let us know what the best practise is to handle this situation.
2 Answer(s)
-
0
Hi,
- Could you share where do you all this method from ?
- Could you also replace CurrentUnitOfWork.SaveChanges() with CurrentUnitOfWork.SaveChangesAsync() and see if it helps ?
Thanks,
-
0
Hi Ismcagdas,
Sorry for the late respose, I think your solution 2 is working fine. Thanks v much.