I am using log4net in a class with multiple threads and I had a simple question. Do I need to enter readlock/writelock when checking properties and calling methods on the log4net.ILog interface?
I am using the suggested method from the log4net examples so at the top of said class I have:
Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(decType)
And since the class involves multiple threads interacting with it, I have a ReaderWriterLockSlim
instance that I use to make sure I don't get into any race conditions with my variables. So to recap,if I want to make sure I'm practicing safe threading do I need to do something like this:
If Me.ReaderWriterLockSlim.TryEnterUpgradableReadLock(-1) Then
If log.IsWarnEnabled Then
If Me.ReaderWriterLockSlim.TryEnterWriteLock(-1) Then
log.Warn("Log Message Here")
Me.ReaderWriterLockSlim.ExitWriteLock()
End If
End If
Me.ReaderWriterLockSlim.ExitUpgradeableReadLock()
End If
Or, can I just simply do this:
If log.IsWarnEnabled Then log.Warn("Log Message Here")
P.S. Yes, that is rough pseudo code, I don't actually have an instance of ReaderWriterLockSlim
that is named 'ReaderWriterLockSlim'.