【问题标题】:Activation error occured while trying to get instance of type LogWriter, key ""尝试获取 LogWriter 类型的实例时发生激活错误,键“”
【发布时间】:2020-10-28 20:52:22
【问题描述】:

我在登录 eventviewer 时收到此错误。我正在事件查看器和滚动平面文件中寻找异常。如果我删除 eventviewer 部分,则滚动平面文件可以完美运行,但只有当我添加它时它才会给出异常

{"依赖解析失败,类型= \"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter\",名称 = \"(none)\"。\r\n出现异常 while: 解析时。\r\n异常 是:InvalidOperationException - TraceListener 类型不能是 建。你必须配置容器来提供这个 值。\r\n-------------------------------------------- ---\r\n在 异常发生的时间,容器是:\r\n\r\n Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter.默认 (映射自 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, (none))\r\n 解析构造函数的参数“structureHolder” Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder 结构持有人, Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider 仪器提供者, Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinator updateCoordinator)\r\n 正在解决 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,LogWriterStructureHolder.默认 (映射自 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder, (none))\r\n 解析构造函数的参数“traceSources” Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder(System.Collections.Generic.IEnumerable1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IEnumerable1[[System.String, mscorlib, 版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089]] 跟踪源名称, System.Collections.Generic.IEnumerable1[[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource allEventsTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource notProcessedTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource errorsTraceSource, System.String defaultCategory, System.Boolean tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch, System.Boolean revertImpersonation)\r\n Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,General\r\n
Resolving parameter \"traceListeners\" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogSource(System.String name, System.Collections.Generic.IEnumerable
1[[System.Diagnostics.TraceListener, 系统,版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089]] 跟踪监听器, System.Diagnostics.SourceLevels 级别,System.Boolean autoFlush, Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider instrumentationProvider)\r\n 正在解决 System.Diagnostics.TraceListener,事件日志跟踪监听器\r\n"}

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    我遇到了同样的问题,这是由于我的配置文件中的错误。我从我的 categorySources 部分引用了跟踪侦听器,这些侦听器在我的侦听器部分中不存在。我删除了类别和映射(无论如何我都没有使用它们),然后它就起作用了。我想您可以在配置控制台中验证您的配置文件,然后它会告诉您问题所在。

    【讨论】:

      【解决方案2】:

      1 - 确保您引用了正确的 DLL

      Microsoft.Practices.EnterpriseLibrary.Logging

      Microsoft.Practices.EnterpriseLibrary.Common

      2 - 确保您的配置文件位于正确的位置(在同一个项目或引用项目中)

      3 - 确保您的配置文件正确。使用 Enterprise Library Configuration Tool 对其进行编辑,没有任何东西应该是红色的。尝试扩展所有跟踪侦听器、类别等。最常见的错误是特殊类别之一指向不存在的侦听器。

      【讨论】:

        【解决方案3】:

        我在使用 ExceptionHanlder 时也有类似的经历。在玩了介绍材料 re:logging 之后,我直接切换到使用 Unity 容器。

        我基本上只是从帮助文件中复制了示例,并简要地想知道为什么它不工作并在类型解析上出错;无法解决。

        答案很简单。在切换到 Unity 容器之前,我只“玩过”日志记录,但我使用/复制的示例同时使用了日志记录和异常处理注入。

        由于我没有“玩过:在 5.0 中使用异常处理,因此配置文件中没有此条目,因此 Unity 无法解析。

        解决方案:使用工具将 ExceptionHandling 块添加到配置文件中需要 5 秒钟,我很高兴继续“玩”。

        Unity 需要配置文件中每个已解析块的条目,即使它们没有命名/自定义。如果您出于学习目的而编写示例代码,这一点非常明显,但很容易被忽略。

        【讨论】:

          【解决方案4】:

          我收到此错误是因为使用不存在的连接字符串设置了数据库侦听器。

          为了帮助诊断,注释掉监听器行,然后一一添加。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-02-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-03-04
            • 1970-01-01
            相关资源
            最近更新 更多