I am writing a global error handler / logger for applications running on Windows Azure. When an error occurs in the application, a series of operations are performed that must be performed atomically. I need the error not to be recorded until the previous one is completed. Meanwhile, I want to read magazines as needed.
My initial thought was to use a monitor / lock and lock only error recording. Thus, reading is not canceled at all. I was wondering if ReaderWriterLockSlim could be more suitable. I cannot say that I really understand the value between one approach and another.
Should I create a ReaderWriterLockSlim and do something like the following below (with reads that will be wrapped in EnterReadLock) ...
public static void LogError(Exception exception)
{
_lock.EnterWriteLock();
...
_lock.ExitWriteLock();
}
Or am I just doing something like the following, blocking only the records:
public static void LogError(Exception exception)
{
lock (someStaticLock)
{
...
}
}
Any thoughts / advice would be highly appreciated.
source
share