I have a VS2015 solution that includes a service layer, which exposes a set of WCF services, and a WPF client that consumes them. I have log4net configured and working fine in the service layer
I now want to use log4net in the client, so added the log4net NuGet package, and copied the node from the service layer's config file into the App.config file for the client. The full file looks like this...
<?xml version="1.0"
encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.5.2" />
</startup>
<log4net>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
<param name="File"
value="PhysioDiary.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="2" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-7level %logger - %message%newline%exception" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="LargeMessageBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="CustomBindingDefault"
closeTimeout="00:59:00"
openTimeout="00:59:00"
receiveTimeout="00:59:00"
sendTimeout="00:59:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="6400"
maxStringContentLength="100000000"
maxArrayLength="2147483647" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
bypassProxyOnLocal="true"
keepAliveEnabled="false"
maxBufferSize="2147483647">
<extendedProtectionPolicy policyEnforcement="Never" />
</httpTransport>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:5448/AppointmentsService.svc"
behaviorConfiguration="LargeMessageBehavior"
binding="customBinding"
bindingConfiguration="CustomBindingDefault"
contract="AppointmentsServiceReference.AppointmentsService"
name="CustomBinding_AppointmentsService" />
<!-- Other WCF services here, snipped for clarity -->
</client>
</system.serviceModel>
</configuration>
Even before using log4net anywhere, if I try to run the client now, I get an exception...
An unhandled exception of type 'System.TypeInitializationException' occurred in PresentationFramework.dll
Additional information: The type initializer for 'System.Windows.Application' threw an exception.
...and the client won't start. It doesn't break on any code, so I can't see a stack trace, nor see if there is an inner exception.
If I comment out the contents of the node, but leave the empty node there, I still get the exception, so it doesn't seem to be the contents of the node, nor the RollingFileAppender that are the problem.
I've checked the references, and both projects have log4net v2.0.5 referenced, and neither have any other log4net references. Both projects use Ninject, although I'm not sure that's relevant as I'm not injecting log4net in either project (yet, that's the next step).
It's not the problem reported in this SO question, as my config file doesn't have appSettings nor configSections. Also, the startup node has always been the first in the file, and this has never caused a problem. I did try moving it to the end, but it didn't help.
Anyone any ideas why it crashes when I try to add log4net to the WPF client?