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

Topics: Enterprise Library Core, Exception Handling Application Block, Logging Application Block, Validation Application Block
Apr 10, 2015 at 9:45 PM
Hello EveryOne,
I have upgraded my web service project from vs 2005 to 2012. My webservice uses a project to log status in event viewer, which inturn uses enterprise library 2.0. Now that i have upgraded, i changed all my configs and dlls to newer version but while debugging i get this following exception.

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

InnerException:

{"Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".
Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type LogWriter 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.Logging.LogWriter,(none)
"}

StackTrace :

at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable
1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)

Could you please help me out with this, as i ve been working on this issue for 3 days now with no luck.

app.config:

<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"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
  <section name="EnService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
</sectionGroup>
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
  <add source="EnService" formatter="Text Formatter" log="MPASLog"
    machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"    />           
</listeners>
<formatters>
  <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
    type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    name="Text Formatter" />
</formatters>
<categorySources>
  <add switchValue="All" name="General">
    <listeners>
      <add name="Formatted EventLog TraceListener" />
    </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="Formatted EventLog TraceListener" />
    </listeners>
  </errors>
</specialSources>
</loggingConfiguration>
<system.diagnostics>
<sources>
  <!-- This section defines the logging configuration for My.Application.Log -->
  <source name="DefaultSource" switchName="DefaultSwitch">
    <listeners>
      <add name="FileLog" />
      <!-- Uncomment the below section to write to the Application Event Log -->
      <!--<add name="EventLog"/>-->
    </listeners>
  </source>
</sources>
<switches>
  <add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
  <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
  <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
  <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<applicationSettings>
<EnService.My.MySettings>
  <setting name="CONST_PRINT_LOG" serializeAs="String">
    <value>1</value>
  </setting>
  <setting name="CONST_JOB_STATUS_SUCCESS" serializeAs="String">
    <value>1</value>
  </setting>
  <setting name="CONST_WEB_SERVICE_TIME_OUT" serializeAs="String">
    <value>10800000</value>
  </setting>
  <setting name="Seperater" serializeAs="String">
    <value>.</value>
  </setting>
  <setting name="EnService_EnServiceWebReference_EnServiceService" serializeAs="String">
    <value>http://localhost/EnServiceService.asmx</value>
  </setting>
  <setting name="PrintFolder" serializeAs="String">
    <value>C:\Jobs\PrintDocuments\</value>
  </setting>
  <setting name="ResultLocation" serializeAs="String">
    <value>C:\Jobs\EnService\Result</value>
  </setting>
  <setting name="ArchiveFilePrefix" serializeAs="String">
    <value>EnService_Report_</value>
  </setting>
  <setting name="ExceptionArchiveFilePrefix" serializeAs="String">
    <value>EnService_Exception_Report_</value>
  </setting>
  <setting name="CONST_PRINT_REPORT" serializeAs="String">
    <value>X</value>
  </setting>
  <setting name="ReportArchiveLocation" serializeAs="String">
    <value>C:\Jobs\EnService\OUT</value>
  </setting>
  <setting name="CommonWebServiceURL" serializeAs="String">
    <value>http://localhost/WebService/Service.asmx</value>
  </setting>
</EnService.My.MySettings>
</applicationSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>

</configuration>

Appreciate your help,

Vin