【问题标题】:EnterpriseLibrary Logger error: Object synchronization method was called from an unsynchronized block of codeEnterpriseLibrary Logger 错误:从未同步的代码块调用了对象同步方法
【发布时间】: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


    【解决方案1】:

    这似乎是一个现有问题:http://unity.codeplex.com/workitem/7206

    好消息是,应该使用 2.1.505.2 版本解决此问题,您可以在以下网址获得:http://nuget.org/packages/Unity/2.1.505.2

    【讨论】:

      猜你喜欢
      • 2012-09-14
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多