Solved

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

Posted on 2014-09-12
1
1,471 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
location of a form 2 25
parsing JSON help 1 20
Need a simple RegEx to search for two words 27 49
Regarding swagger API 1 17
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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