Exception merging Configuration Files

Topics: Logging Application Block
Nov 18, 2011 at 9:36 AM

Hi, this is a long story, you might want to get a cup of tea.

Okay, so I am trying to write an application using Silverlight, Prism, and EntLib for my Logging and Exception handling.

I've got most of the pieces to play together and as this is my first time using the Enterprise Library I decided to use the
StockTraderRI as my guidance.

As in the StocktraderRI project I am also downloading Xaml Configuration file and this is where I'm experiencing the problem.

My code for merging the Files. (I've marker where the exception occurs with a arrow <--)

private void MergeXamlFile(string xamlFileContent)
{
    var content = (IDictionary)XamlReader.Load(xamlFileContent); <--
    foreach (var key in content.Keys.OfType<string>())
    {
        var section = content[key] as ConfigurationSection;
        if (section != null)
        {
            this.mergedConfiguration.Add(key, section);
        }
    }
}

 

The Exception message is : Failed to create a 'Microsoft.Practices.EnterpriseLibrary.Logging.Service.ILoggingServiceFactory' from the text 'LoggingServiceEndPoint'. [Line: 9 Position: 85]

The line in the xaml configuration file is below, when I remove it, I don't get and exception. (marked with an arrow -->)

<el:ConfigurationDictionary 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"
                    xmlns:inf="clr-namespace:StockTraderRI.Infrastructure.ExceptionHandling;assembly=StockTraderRI.Infrastructure">
    <el:LoggingSettings DefaultCategory="default" x:Key="loggingConfiguration" LogWarningWhenNoCategoriesMatch="False">
        <el:LoggingSettings.TraceListeners>
            <el:NotificationTraceListenerData Name="event"/>
            <el:IsolatedStorageTraceListenerData Name="isolated" RepositoryName="LogMessagesInIsolatedStorage" MaxSizeInKilobytes="256"/>
--->        <el:RemoteServiceTraceListenerData Name="service" LoggingServiceFactory="LoggingServiceEndpoint" SubmitInterval="00:01:00" IsolatedStorageBufferMaxSizeInKilobytes="256" MaxElementsInBuffer="200"/>
        </el:LoggingSettings.TraceListeners>

<--  Rest of the setting removed for brevity --> </el:ConfigurationDictionary>

I'm using exactly the same configuration as the StockTraderRI, I'm doing this until I can get it to work, then I'll make the changes where required.
For the LoggingServiceFactory I'm again using the code from the StockTraderRI, I've got a ServiceReference.ClientConfig in the core silverlight application
with some slight changes to point to my Enterprise Library service implementation.

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
		<binding name="CustomBinding_ILoggingService">
		    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
		</binding>
            </basicHttpBinding>
        </bindings>
        <client>
	    <endpoint address="../Service/LogginServiceEntLib.svc"
		binding="customBinding" bindingConfiguration="CustomBinding_ILoggingService" contract="Microsoft.Practices.EnterpriseLibrary.Logging.Service.ILoggingService" name="LoggingServiceEndpoint" />
        </client>
    </system.serviceModel>
</configuration>

and then I have the same settings in my web.config as well (I've only included the tasty bits here)

 

<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="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
	<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>

<system.serviceModel>
	<behaviors>
		<serviceBehaviors>
			<behavior name="">
				<serviceMetadata httpGetEnabled="true" />
				<!-- for debugging the service, turn this to true and 
				change the networking stack in the client where the call is made. 
				WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp); -->
				<serviceDebug includeExceptionDetailInFaults="false" />
			</behavior>
		</serviceBehaviors>
	</behaviors>
	<bindings>
		<customBinding>
			<binding name="Microsoft.Practices.EnterpriseLibrary.Logging.Service.customBinding0">
				<binaryMessageEncoding />
				<httpTransport />
			</binding>
		</customBinding>			
	</bindings>
	<services>
		<service name="SBaseApplication.Web.Service.ExtendedLoggingService">
			<endpoint address="" binding="customBinding" bindingConfiguration="Microsoft.Practices.EnterpriseLibrary.Logging.Service.customBinding0" contract="Microsoft.Practices.EnterpriseLibrary.Logging.Service.ILoggingService" />
			<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
		</service>
	</services>
	<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<!--#########################################################################################--> <!-- Configuration section for logging --> <!--#########################################################################################-->   <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"> <listeners> <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" source="Enterprise Library Logging" formatter="Text Formatter" log="" machineName="." traceOutputOptions="None" /> <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" fileName="trace.log" formatter="Text Formatter" /> <add name="In Memory Trace Listener" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" type="StockTraderRI.Logging.InMemoryTraceListener, StockTraderRI.Web" formatter="Text Formatter" /> </listeners> <formatters> <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging" 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" /> <add switchValue="All" name="Validation"> <listeners> <add name="Flat File Trace Listener" /> </listeners> </add> <add switchValue="Error" name="Exception"> <listeners> <add name="Event Log Listener" /> </listeners> </add> </categorySources> <specialSources> <allEvents switchValue="All" name="All Events"> <listeners> <add name="In Memory Trace Listener" /> </listeners> </allEvents> <notProcessed switchValue="All" name="Unprocessed Category"> <listeners> <add name="In Memory Trace Listener" /> </listeners> </notProcessed> <errors switchValue="All" name="Logging Errors &amp; Warnings"> <listeners> <add name="Event Log Listener" /> </listeners> </errors> </specialSources> </loggingConfiguration>

 

 

So, after aaall of that, I'm hoping someone says, hey change that 1 to a 0 and everything will work. 
But seriously, what I'm I missing here. any help would be appreciated as I'm loosing hair... fast.

Thanks

Nov 18, 2011 at 4:28 PM

I had the same issue, I didn't use all the StocktradeRI infrasturcture classes in my sample , so I removed   xmlns:inf="clr-namespace:StockTraderRI.Infrastructure.ExceptionHandling;assembly=StockTraderRI.Infrastructure"

and removed all the elements refering inf: prefix in the configuration file, eveything start working. Give it a try , if you are alos in the same scenario.

Nov 21, 2011 at 6:36 AM

Thanks cbaski, I tried your suggestion but it didn't help, I'm still getting the same exception.

To me, it looks like the problem is that the EntLib logging blocks cannot be resolved the WCF Endpoint.
I don't know if that an issue with the way my WCF service is set up or if its related to referencing the
EntLib libraries themselves.

I'll keep at it until something breaks.... me or the monitor...

Thanks for the suggestion

Nov 21, 2011 at 10:08 PM

It looks like you have mismatched binding configuration between the client and service (specifically the binaryMessageEncoding).

Try this as your ServiceReference.ClientConfig:

<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="CustomBinding_ILoggingService">
          <binaryMessageEncoding />
          <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="../Service/LogginServiceEntLib.svc"
		binding="customBinding" bindingConfiguration="CustomBinding_ILoggingService" 
		contract="Microsoft.Practices.EnterpriseLibrary.Logging.Service.ILoggingService" 
		name="LoggingServiceEndpoint" />
    </client>
  </system.serviceModel>
</configuration>

 

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Marked as answer by randylevy on 7/6/2014 at 10:06 PM
Nov 22, 2011 at 12:29 PM

Randy!, clearly I just needed to change that 1 to a 0 and it worked perfectly. I've been hammering at
this for a day or two and I knew it would just be a small change to fix it.

Thank you very much for spotting that, you've just saved the life of a monitor.