0

mvvm-light Framework を使用して、Silverlight で Enterprise Library 5.0 を使用しています。次のような ExceptionManager クラスの getInstace を実行する場合:

 var exceptionManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
  exceptionManager.HandleException(E.Error, "Policy");

このタイプのエラーメッセージが表示されました

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

Resolution of the dependency failed, type = Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager", name = "(none)"
  Exception occurred while: while resolving.Exception is: InvalidOperationException - The type TraceListener cannot be constructed. You must configure the container to supply this value
 -----------------------------------------------
 At the time of the exception, the container was:

 Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManagerImpl,ExceptionManager.__default__ (mapped from Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager, (none))
Resolving parameter "exceptionPolicies" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManagerImpl(System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] exceptionPolicies, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Instrumentation.IDefaultExceptionHandlingInstrumentationProvider instrumentationProvider)
Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl,Policy
Resolving parameter "policyEntries" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl(System.String policyName, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] policyEntries)
  Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry,Policy.All Exceptions
  Resolving parameter "handlers" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry(System.Type exceptionType, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.PostHandlingAction postHandlingAction, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] handlers, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Instrumentation.IExceptionHandlingInstrumentationProvider instrumentationProvider)
    Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,Policy.All Exceptions.Logging Exception Handler (mapped from Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler, Policy.All Exceptions.Logging Exception Handler)
    Resolving parameter "writer" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler(System.String logCategory, System.Int32 eventId, Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.TraceEventType severity, System.String title, System.Int32 priority, System.Type formatterType, Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter writer)
      Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter.__default__ (mapped from Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, (none))
      Resolving parameter "structureHolder" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder structureHolder, Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider instrumentationProvider, Microsoft.Practices.EnterpriseLibrary.Logging.IAsyncTracingErrorReporter asyncTracingErrorReporter)
        Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,LogWriterStructureHolder.__default__ (mapped from Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder, (none))
        Resolving parameter "traceSources" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder(System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight, Version=5.0.505.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] traceSourceNames, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight, Version=5.0.505.1, 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)
          Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,General
          Resolving parameter "traceListeners" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogSource(System.String name, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.TraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight, Version=5.0.505.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceListeners, Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.SourceLevels level, System.Boolean autoFlush, Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider instrumentationProvider)
            Resolving Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.TraceListener,Flat File Trace Listener

の行で

 var exceptionManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();

私の構成ファイルは次のとおりです。

   <?xml version="1.0" encoding="utf-8"?>
    <ResourceDictionary           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:el="http://schemas.microsoft.com/practices/2011/entlib">
     <el:ExceptionHandlingSettings x:Key="exceptionHandling">
     <el:ExceptionHandlingSettings.ExceptionPolicies>
     <el:ExceptionPolicyData Name="LogPolicy">
     <el:ExceptionPolicyData.ExceptionTypes>
      <el:ExceptionTypeData Name="All Exceptions" TypeName="System.Exception, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
        <el:ExceptionTypeData.ExceptionHandlers>
          <el:LoggingExceptionHandlerData LogCategory="General" FormatterTypeName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Priority="-1" Name="Logging Exception Handler" />
        </el:ExceptionTypeData.ExceptionHandlers>
      </el:ExceptionTypeData>
    </el:ExceptionPolicyData.ExceptionTypes>
  </el:ExceptionPolicyData>
 </el:ExceptionHandlingSettings.ExceptionPolicies>
 </el:ExceptionHandlingSettings>
 <el:LoggingSettings DefaultCategory="General" x:Key="loggingConfiguration">
  <el:LoggingSettings.TraceSources>
  <el:TraceSourceData Name="General">
    <el:TraceSourceData.TraceListeners>
      <el:TraceListenerReferenceData Name="Flat File Trace Listener" />
    </el:TraceSourceData.TraceListeners>
  </el:TraceSourceData>
 </el:LoggingSettings.TraceSources>
 <el:LoggingSettings.SpecialTraceSources>
  <el:SpecialTraceSourcesData>
    <el:SpecialTraceSourcesData.AllEventsTraceSource>
      <el:TraceSourceData Name="All Events" />
    </el:SpecialTraceSourcesData.AllEventsTraceSource>
    <el:SpecialTraceSourcesData.NotProcessedTraceSource>
      <el:TraceSourceData Name="Unprocessed Category" />
    </el:SpecialTraceSourcesData.NotProcessedTraceSource>
    <el:SpecialTraceSourcesData.ErrorsTraceSource>
      <el:TraceSourceData Name="Logging Errors &amp; Warnings">
        <el:TraceSourceData.TraceListeners>
          <el:TraceListenerReferenceData Name="Flat File Trace Listener" />
        </el:TraceSourceData.TraceListeners>
      </el:TraceSourceData>
    </el:SpecialTraceSourcesData.ErrorsTraceSource>
  </el:SpecialTraceSourcesData>
  </el:LoggingSettings.SpecialTraceSources>
  </el:LoggingSettings>
  </ResourceDictionary>
4

1 に答える 1

1

構成が「フラット ファイル トレース リスナー」と呼ばれるトレース リスナーを参照しているように見えますが、その名前で定義されたトレース リスナーはありません。

また、Enterprise Library Silverlight Logging Application Block はフラット ファイル トレース リスナーをサポートしていないことに注意してください。有効なアクションは次のとおりです。

  • リモート WCF サービスへのログ記録。
  • 分離ストレージへのログ記録。
  • イベントへのロギング。
于 2012-05-02T05:11:06.103 に答える