Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

14 Experts available now in Live!

Get 1:1 Help Now