Enterprise Library 6 LogCallHandler throwing exception "The LogWriter has not been set for the Logger static class"
Asked Answered
P

2

7

Guys

I'm trying using LogCallHandler into Interception like this:

<interception>
        <policy name="policyLogCallHandler">
          <matchingRule name="LogsMachingRule" type="NamespaceMatchingRule">
            <constructor>
              <param name="namespaceName" value="NetTcpContracts" />
            </constructor>
          </matchingRule>
          <callHandler type="Microsoft.Practices.EnterpriseLibrary.Logging.PolicyInjection.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="callHandlerLog">
            <constructor>
              <param name="eventId" value="9002"/>
              <param name="logBeforeCall" value="true"/>
              <param name="logAfterCall" value="true"/>
              <param name="beforeMessage" value="--- begin"/>
              <param name="afterMessage" value="--- end"/>
              <param name="includeParameters" value="true"/>
              <param name="includeCallStack" value="true"/>
              <param name="includeCallTime" value="true"/>
              <param name="priority" value="1"/>
              <param name="order" value="1"/>
            </constructor>            
          </callHandler>
        </policy>        
      </interception>

This configuration throw a exception: "The LogWriter has not been set for the Logger static class. Set it invoking the Logger.SetLogWriter method."

I found solutions for this problem using runtime configuration:

IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
Logger.SetLogWriter(logWriterFactory.Create());
LogEntry entry = new LogEntry();
entry.Message = "I am logging";
Logger.Write(entry)

But, I'm using configuration through config file. How to reproduce this behavior in config file?

Tks!

Philanthropic answered 21/3, 2014 at 12:26 Comment(0)
B
5

The boostrapping behavior of Enterprise Library has changed in Version 6. The impact for the static Logger facade is that you need to set the internal LogWriter (for example at application start): For more details refer https://entlib.codeplex.com/discussions/442089

Thanks

Backdrop answered 9/4, 2015 at 8:49 Comment(0)
J
1

Was facing the same error today, I just removed latest version of EL logging block and installed 5.0.505.1 version of it using nuget package manager and it worked.

Joesphjoete answered 12/2, 2015 at 14:35 Comment(1)
I also had to fix the bindingRedirects to get it workingMelleta

© 2022 - 2024 — McMap. All rights reserved.