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

use*_*339 16 c# enterprise

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

Logger.Write(msg);
Run Code Online (Sandbox Code Playgroud)

尝试记录时,我收到"尝试获取LogWriter类型的实例时出现激活错误"错误消息.

下面显示的是MS Enterprise库使用的配置文件

<?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>
Run Code Online (Sandbox Code Playgroud)

Eth*_*wne 14

我只想添加此错误可能是由另一个配置问题引起的.请务必查看此错误的内部异常.在我的情况下它是:

"无法构建类型数据库.您必须配置容器以提供此值."

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

 <add name="DBConn" connectionString="Data Source=ServerName;Initial Catalog=Logging;Persist Security Info=True;integrated security=True;" providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢,我为这个问题尝试了很多与GAC相关的解决方案,直到这个问题才有效. (2认同)
  • 最简单的事情通常需要很长时间才能解决,因为编码人员只是积极地测试而不考虑软件在出现问题时应该如何表现! (2认同)

use*_*339 11

我意识到我试图在一个不起作用的DLL中使用Config文件.我应该使用FileConfigurationSource代替.

如果我从一个应用程序使用相同的App.Config,它工作正常.