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.