I started getting this error when logging using the MS Enterprise Library Logger.
The logging mechanism works my queuing the log entries and then using the timer to flush the entries every 10 seconds.
It was working fine for a while, but today this error started to appear:
Line of code:
Logger.Write(list[i]);
Error Message:
Object synchronization method was called from an unsynchronized block of code.
Stack Trace:
at Microsoft.Practices.Unity.SynchronizedLifetimeManager.TryExit()
Entire timer elsapsed event handler:
private void TimerElapsed(object sender, ElapsedEventArgs e)
{
// Lock and free free the queue quickly - write to an intermediate list.
var list = new List<LogEntry>();
lock (LogEntryQueueLock)
{
while (true)
{
if (_logEntryQueue.Count <= 0)
break;
//dequeue the LogEntry that will be written to the log
list.Add(_logEntryQueue.Dequeue());
}
}
// Flush the list in to the log
for (int i = 0; i < list.Count; i++)
{
ProcessEntry(list[i]); // Strip commas from the string
Logger.Write(list[i]); // <<<== ERRORS HERE
}
}
Many thanks for any suggestions!
[EDIT]: I tried to call Logger.Write direclty, without the timer elapsed event - same problem...