2016-05-26 19 views
1

既存のアプリケーションを5から6にアップグレードしています。私のアプリケーションは.NET Webアプリケーションです。私はデータベース(SQLサーバー)にエラーを記録するためにエンタープライズライブラリに依存しています。エンタープライズライブラリ5から6へのアプリケーションのアップグレード

私のアプリケーションでは、カスタムデータベースリスナーとカスタムログ出力例外ハンドラ(どちらも私のソリューション内で別々の.netプロジェクトの形で)を使用しています。だから、

、私は6がインストールされている、そしてそれはLogger.SetLogWriter当たったとき、私はSystem.NotImplementedExceptionを得る

   IConfigurationSource config = ConfigurationSourceFactory.Create(); 
     ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config); 
     Logger.SetLogWriter(new LogWriterFactory().Create()); 

     ExceptionManager exceptionManager = factory.CreateManager(); 

をApplication_Start-するには、次のコードを追加した(新しいLogWriterFactoryを()。()を作成します) ;コード行

EDIT:より具体的なエラーの詳細

System.NotImplementedException was unhandled by user code 
HResult=-2147467263 
Message=Must be implemented by subclasses. 
Source=Microsoft.Practices.EnterpriseLibrary.Logging 

私が間違って何をしているのですか?正しい道に私を取得するため@lrbする ありがとう:

は、ここに私のweb.config-

<configSections> 
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" requirePermission="true" /> 
<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> 
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"> 
<listeners> 
    <add name="Database Trace Listener" type="ExtendedPropertyDatabaseListener.ExtendedFormattedDatabaseTraceListener, ExtendedPropertyDatabaseListener" listenerDataType="ExtendedPropertyDatabaseListener.ExtendedFormattedDatabaseTraceListenerData, ExtendedPropertyDatabaseListener" databaseInstanceName="ablmprod" writeLogStoredProcName="Logging.WriteLog" addCategoryStoredProcName="Logging.AddCategory" formatter="Text Formatter" /> 
    <add name="Event Log Trace 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="Enterprise Library Logging" formatter="Text Formatter" /> 
</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;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="Database Trace 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 Trace Listener" /> 
    </listeners> 
    </errors> 
</specialSources> 
</loggingConfiguration> 
<exceptionHandling> 
    <exceptionPolicies> 
    <add name="Policy"> 
    <exceptionTypes> 
     <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow"> 
     <exceptionHandlers> 
      <add name="Logging Exception Handler" type="CustomExceptionLoggingHandler.CustomExceptionLoggingHandler, CustomExceptionLoggingHandler" logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0" /> 
     </exceptionHandlers> 
     </add> 
    </exceptionTypes> 
    </add> 
</exceptionPolicies> 
</exceptionHandling> 

EDITです。ここでは、動作したコードです -

protected void Application_Start() 
{ 
    LoggingConfiguration loggingConfiguration = BuildLoggingConfig(); 
    LogWriter logWriter = new LogWriter(loggingConfiguration); 
    Logger.SetLogWriter(logWriter, false); 
    ExceptionPolicy.SetExceptionManager(exManager); 

    // Create the default ExceptionManager object programatically 
    exManager = BuildExceptionManagerConfig(logWriter); 

    // Create an ExceptionPolicy to illustrate the static HandleException method 
    ExceptionPolicy.SetExceptionManager(exManager); 

      ... 
} 

private static LoggingConfiguration BuildLoggingConfig() 
{ 
    // Formatters 

    var config = new LoggingConfiguration(); 

    return config; 
} 

private static ExceptionManager BuildExceptionManagerConfig(LogWriter logWriter) 
{ 
    var policies = new List<ExceptionPolicyDefinition>(); 

    var logAndWrap = new List<ExceptionPolicyEntry> 
      { 

       new ExceptionPolicyEntry(typeof (Exception), 
        PostHandlingAction.ThrowNewException, 
        new IExceptionHandler[] 
        { 
         new WrapHandler("An application error has occurred.", 
         typeof(APIAvailabilityException)) 
        }) 
      }; 

    policies.Add(new ExceptionPolicyDefinition("Policy", logAndWrap)); 

    return new ExceptionManager(policies); 
} 

答えて

0

少し変わっています。ダミーのConfugurationSourceが必要です。これは、すべてのものがそのままで、私のために機能します。 SetLogWriterメソッドのオプションのThrowIfSetパラメータに注目してください。ドキュメントは次のように述べています。

throwIfSetライターが既に設定されている場合は例外をスローします。そうでなければfalse。デフォルトはtrueです。まだこの問題と推奨ソリューションが動作しません持っている人のための

IConfigurationSource configurationSource = ConfigurationSourceFactory.Create(); 
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);     
Logger.SetLogWriter(logWriterFactory.Create(),false); 
Logger.Write(le); 
+1

私はまだ同じエラーを取得します。 – Chris

0

もう少し情報。

CoreBuildTraceListenerメソッドは、カスタムTraceListenerDataクラス(使用する場合)に実装されていない可能性があります。私はそれを動作させるために以下を追加しなければならなかった私の場合は

(コードは私の実装に固有のものです):

protected override TraceListener CoreBuildTraceListener(LoggingSettings settings) 
{ 
    return new RollingXmlTraceListener(
     this.FileName, 
     this.RollSizeKB, 
     this.TimeStampPattern, 
     this.RollFileExistsBehavior, 
     this.RollInterval, 
     this.MaxArchivedFiles); 
} 
関連する問題