I'm facing following problem: In my project, I have done error logging into the same DB, as the application is using. That means, that if error occurs, then in each catch, there is the error stored into DB. The problem is however, when using transactions. When error occurs, the tran rollbacks, but it also rollbacks the error logged, like in this scenario:
this is public service, used to save client changes.
public UpdateClient(client)
{
try
{
TransactionScope scope0 = new TransactionScope();
// some code
scope0.Complete();
}
catch(Exception ex)
{
Logger.LogException(ex); //log the exception into DB
}
}
this is public service, used to multiple clients changes:
public void UpdateClients(clients)
{
try
{
TransactionScope scope1 = new TransactionScope();
foreach (client c in clients)
{
UpdateClient(c);
}
scope1.Complete();
}
catch (Exception ex)
{
Logger.LogException(ex);
}
}
What happend here is, that if using UpdateClients(), and if error occurs in UpdateClient(), then it is logged into DB in UpdateClient() catch block. The scope0 is rollbacked, and doesnt affect the logged exception. But the scope1 is also rollbacked, and will rollback also the exception stored in DB in the UpdateClient() catch block.
I know, that there are options like store the errors in different DB and so on, but this is unfortunately not acceptible in current state of development. Is there any way, how to solve this problem without major changes?