c# - 尝试获取 LogWriter 类型的实例时发生激活错误

标签 c# enterprise

我正在尝试使用 Enterprise Library 5.0 的日志记录应用程序 block 将简单消息记录到 Win XP SP3 系统上的 Windows 事件日志中:

Logger.Write(msg);

我在尝试记录时收到“尝试获取 LogWriter 类型的实例时发生激活错误”错误消息。

下面显示的是与 MS 企业库一起使用的配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
        <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            source="Enterprise Library Logging" formatter="Text Formatter"
            log="Application" machineName="." traceOutputOptions="None" />
    </listeners>
    <formatters>
        <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
            name="Text Formatter" />
    </formatters>
    <categorySources>
        <add switchValue="All" name="General">
            <listeners>
                <add name="Event Log Listener" />
            </listeners>
        </add>
    </categorySources>
    <specialSources>
        <allEvents switchValue="All" name="All Events" />
        <notProcessed switchValue="All" name="Unprocessed Category" />
        <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
                <add name="Event Log Listener" />
            </listeners>
        </errors>
    </specialSources>
</loggingConfiguration>
</configuration>

最佳答案

我只是想添加这个错误可能是由另一个配置问题引起的。确保查看此错误的内部异常。在我的例子中是:

“无法构造数据库类型。您必须配置容器以提供此值。”

为了解决这个问题,我必须在 web.config 中将 providerName 添加到我的数据库连接字符串中。所以最终的连接字符串节点看起来像这样:

 <add name="DBConn" connectionString="Data Source=ServerName;Initial Catalog=Logging;Persist Security Info=True;integrated security=True;" providerName="System.Data.SqlClient" />

关于c# - 尝试获取 LogWriter 类型的实例时发生激活错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2900403/

相关文章:

c# - 如何为表单设置 "preferred size"?

windows-phone-8 - Windows Embedded 8 手持设备 (WE8H) 支持的设备

ios - 是否可以在 iOS 上下载并运行代码

enterprise - 企业应用程序每天重启还是 100% 正常运行?

android - 一个移动应用程序可以支持多个不同的 MDM 吗?

ios - 带有自定义启动器的 Kiosk 模式下的 iPad

c# - 如何继承父常量并访问它们?

C# 为结构错误的属性赋值

c# - 从 .BAT 运行带有 .application 文件类型的 c# 控制台应用程序

c# - 错误 - 具有多个数据库连接的 LINQ/TransactionScope