我正在使用 NLog。当我尝试像这样初始化我的记录器对象时:
private static Logger _logger = LogManager.GetCurrentClassLogger();
我得到:
2012-11-22 10:15:33.8479|Error|MyClass(6468:13)|MyNamespace.BaseThreadLoop|Exception processing event in RequestLoop: System.TypeInitializationException: The type initializer for 'MyClass' threw an exception. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at NLog.Internal.EnumerableHelpers.<OfType>d__0`1.MoveNext() in c:\NLogBuild\src\NLog\Internal\EnumerableHelpers.cs:line 60
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at NLog.Internal.EnumerableHelpers.ToList[T](IEnumerable`1 enumerable) in c:\NLogBuild\src\NLog\Internal\EnumerableHelpers.cs:line 118
at NLog.Internal.ObjectGraphScanner.ScanProperties[T](List`1 result, Object o, Int32 level, Dictionary`2 visitedObjects) in c:\NLogBuild\src\NLog\Internal\ObjectGraphScanner.cs:line 118
at NLog.Internal.ObjectGraphScanner.ScanProperties[T](List`1 result, Object o, Int32 level, Dictionary`2 visitedObjects) in c:\NLogBuild\src\NLog\Internal\ObjectGraphScanner.cs:line 125
at NLog.Internal.ObjectGraphScanner.ScanProperties[T](List`1 result, Object o, Int32 level, Dictionary`2 visitedObjects) in c:\NLogBuild\src\NLog\Internal\ObjectGraphScanner.cs:line 125
at NLog.Internal.ObjectGraphScanner.ScanProperties[T](List`1 result, Object o, Int32 level, Dictionary`2 visitedObjects) in c:\NLogBuild\src\NLog\Internal\ObjectGraphScanner.cs:line 125
at NLog.Internal.ObjectGraphScanner.FindReachableObjects[T](Object[] rootObjects) in c:\NLogBuild\src\NLog\Internal\ObjectGraphScanner.cs:line 65
at NLog.Internal.TargetWithFilterChain.PrecalculateStackTraceUsage() in c:\NLogBuild\src\NLog\Internal\TargetWithFilterChain.cs:line 95
at NLog.LogFactory.GetTargetsByLevelForLogger(String name, IList`1 rules, TargetWithFilterChain[] targetsByLevel, TargetWithFilterChain[] lastTargetsByLevel) in c:\NLogBuild\src\NLog\LogFactory.cs:
line 587
at NLog.LogFactory.GetTargetsByLevelForLogger(String name, IList`1 rules, TargetWithFilterChain[] targetsByLevel, TargetWithFilterChain[] lastTargetsByLevel) in c:\NLogBuild\src\NLog\LogFactory.cs:
line 574
at NLog.LogFactory.GetConfigurationForLogger(String name, LoggingConfiguration configuration) in c:\NLogBuild\src\NLog\LogFactory.cs:line 599
at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey) in c:\NLogBuild\src\NLog\LogFactory.cs:line 717
at NLog.LogFactory.GetLogger(String name) in c:\NLogBuild\src\NLog\LogFactory.cs:line 330
at NLog.LogManager.GetCurrentClassLogger() in c:\NLogBuild\src\NLog\LogManager.cs:line 143
at MyNamespace.MyOtherClass..cctor() in C:\....cs:line 25
--- End of inner exception stack trace ---
at MyNamespace.MyClass.get_Instance()
...
我按照http://nlog-forum.1685105.n2.nabble.com/InvalidOperationException-when-accessing-the-configuration-from-multiple-threads-td6723806.html的建议将我的内存目标移动到一个单独的类,但是仍然有问题。任何想法?