Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 456
Richard Bezerra Avatar asked Mar 21 '14 12:03

Richard Bezerra


2 Answers

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

like image 157
Nilesh Sawant Avatar answered Sep 19 '22 15:09

Nilesh Sawant


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.

like image 29
IsmailS Avatar answered Sep 20 '22 15:09

IsmailS