Solved

Why is log4Net not generating a log file in my WCF service?

Posted on 2014-09-12
1
1,375 Views
Last Modified: 2014-10-07
Hi:

I'm currently having difficulty getting log4net working in my WCF service application.
I'm running the service through VS 2010 (iis express)
I don't see any build errors or run time exceptions.
But the desired log file is not getting generated.

The WCF service implementation is broken into 2 parts (service library and service)
TestServiceLibrary.dll
TestService.dll

This is what the log4net configuration look like in my app.config file:
TestServiceLibrary -> App.config


  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
  </configSections>
  <log4net debug="false">
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="C:\\logs\\TestService_log.txt"/>
      <!-- the file to write to. change for your location and service -->
      <appendToFile value="true"/>
      <immediateFlush value="true" />
      <datePattern value="yyyyMMdd"/>
      <rollingStyle value="Date"/>
      <!-- defines what the log message looks like. you want the timestamp and message, the rest is more or less decoration -->
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
      </layout>
    </appender>
    <appender name="DebugAppender" type="log4net.Appender.DebugAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
      </layout>
    </appender>
    <root>
      <level value="DEBUG"/>
      <!-- determines what 'level' of message to output. take as-is -->
      <appender-ref ref="RollingLogFileAppender" />
      <appender-ref ref="DebugAppender"/>
    </root>
  </log4net>

Open in new window



Actual calls to Log4net takes place in TestServiceLibrary.dll:
This my code snippet
private static ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
m_log.Debug("Debug Test Log4Net write");
m_log.Debug("Info Test Log4Net write");

Open in new window


When I examine m_log at run time, all the following fields are set to false:
IsDebugEnabled
IsErrorEnabled
IsFatalEnabled
IsInfoEnabled
IsWarningEnabled

Open in new window

0
Comment
Question by:jxbma
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40323305
Does the web service have access rights to the C:\Logs folder?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now