簡體   English   中英

Enterprise Library 5.0登錄ASP.Net Web服務項目-激活錯誤

[英]Enterprise Library 5.0 Logging in ASP.Net Webservice project - Activation error

嘗試使用企業庫5.0記錄錯誤時,我收到以下異常:

Activation error occured while trying to get instance of type LogWriter, key \"\""

內部異常消息1:

"Resolution of the dependency failed, 
type = \"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter\", 
name = \"(none)\".

內部異常消息2:

The type LogWriter cannot be constructed. 
You must configure the container to supply this value."

這是代碼:

public static void WriteException(Exception ex, string title)
{
    try
    {
        LogEntry logEntry = new LogEntry()
        {
            Title = title,
            Message = ex.Message,
            Severity = TraceEventType.Error,
            TimeStamp = DateTime.Now
        };

        Logger.Write(logEntry);         
    }
    catch (Exception exception)
    {

    }
}

這是我的Web.config:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
  </configSections>
  <dataConfiguration defaultDatabase="OracleConnection">
    <providerMappings>
      <add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data" name="Oracle.DataAccess.Client"/>
    </providerMappings>
  </dataConfiguration>
  <connectionStrings>
    <add name="PortalAdminContext" connectionString="Data Source=|DataDirectory|PortalAdmin.sdf" providerName="System.Data.SqlServerCe.4.0"/>
    <add name="OracleConnection" connectionString="" providerName="Oracle.DataAccess.Client"/>
    <add name="PersonalizationConnection" connectionString="" providerName="Oracle.DataAccess.Client"/>
  </connectionStrings> 

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SqlServerCe.4.0"/>
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    </DbProviderFactories>
  </system.data>
  <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.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           source="PortalWebservice"
           formatter="Text Formatter"
           log="Portal"
           machineName="."
           traceOutputOptions="DateTime, Timestamp"
           filter="All"/>
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{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">
        <listeners>
          <add name="Event Log Listener"/>
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Event Log Listener"/>
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Event Log Listener"/>
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>

“門戶”事件日志已創建。

相同的代碼和相同的配置在其他項目中也可以正常工作。 但是,我在嘗試登錄時在ASP .Net Web服務中收到激活錯誤。 似乎在嘗試創建LogWriter時找不到Web.config。

我注意到其他項目在企業庫的數據庫部分開始遇到相同的“激活錯誤”,並且更多的調查使我進入了.Net Framework 2.0和3.5的machine.config。 在machine.config和Oracle數據提供程序的項目web.config中有一個公共條目。 向web.config中添加以下條目可更正其他項目中的“激活錯誤”,並更正了上述項目中的LogWriter激活錯誤:

<system.data>
    <DbProviderFactories>      
      <remove invariant="Oracle.DataAccess.Client"/>
      <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.102.2.20, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </DbProviderFactories>
  </system.data>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM