3
我在使用MS Enterprise Library Logger進行記錄時開始出現此錯誤。EnterpriseLibrary記錄器錯誤:從未同步的代碼塊調用對象同步方法
日誌機制工作我排隊日誌條目,然後使用計時器每10秒刷新條目。
這是工作的罰款了一段時間,但今天這個錯誤開始出現:
行代碼:
Logger.Write(list[i]);
錯誤消息:
Object synchronization method was called from an unsynchronized block of code.
堆棧跟蹤:
at Microsoft.Practices.Unity.SynchronizedLifetimeManager.TryExit()
整個計時器elsapsed事件處理程序:
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
}
}
非常感謝您的任何建議!
[編輯]:我想將照片直接調用Logger.Write,而計時器經過事件 - 同樣的問題...