【发布时间】:2013-01-05 06:22:51
【问题描述】:
我在使用 MS Enterprise Library Logger 进行记录时开始收到此错误。
日志机制使我将日志条目排队,然后使用计时器每 10 秒刷新一次条目。
前段时间还好好的,今天开始出现这个错误:
代码行:
Logger.Write(list[i]);
错误信息:
Object synchronization method was called from an unsynchronized block of code.
堆栈跟踪:
at Microsoft.Practices.Unity.SynchronizedLifetimeManager.TryExit()
整个计时器已结束事件处理程序:
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,而没有计时器经过事件 - 同样的问题...
【问题讨论】:
标签: c# logging asynchronous unity-container enterprise-library