views:

2551

answers:

6

We are trying to use Log4Net to log from our IIS 6-deployed WCF Application. We are trying to log to a file, but can't seem to get the log files to be created, let alone see the logging output in them. The pertinent pieces of out web.config are:

<sectionGroup name="common">
    <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
...
<common>
    <logging>
        <factoryAdapter type="Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging">
            <arg key="level" value="INFO" />
            <arg key="showLogName" value="true" />
            <arg key="showDataTime" value="true" />
            <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
        </factoryAdapter>
    </logging>
</common>

<log4net>
    <appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="c:\logs\ApplicationInfoTest.log" />
        <threshold value="INFO" />
        <param name="AppendToFile" value="true" />
        <param name="DatePattern" value="ddMMyyyy" />
        <param name="MaxSizeRollBackups" value="10" />
        <param name="MaximumFileSize" value="10MB" />
        <param name="RollingStyle" value="Size" />
        <param name="StaticLogFileName" value="true" />
        <layout type="log4net.Layout.PatternLayout">
            <param name="Header" value="\r\n\r\n---------------------------------------------\r\n" />
            <param name="Footer" value="\r\n---------------------------------------------\r\n\r\n" />
            <param name="ConversionPattern" value="%d [%t] %-5p - %m%n" />
        </layout>
    </appender>
    <root>
        <level value="INFO" />
        <appender-ref ref="FileAppender" />
    </root>
  </log4net>

With this configuration we can see INFO level logging coming out of our application when using DebugView, but it is clear that this is from the piece and not the
piece.

Is there something that we have failed to set up in web.config? Is it a permissions issue with the directory we have created for the logs to be written to?

Please point out our obvious mistake.

+1  A: 

Use ProcessMonitor from SysInternals to find out where permissions are being refused

(Potentially you can determine the same info by attaching a debugger and trapping on exceptions, not in Just My Code)

Are you sure that the process under which the service is running has permissions on the folder you're trying to write to?

Ruben Bartelink
Hi Ruben. Thanks for the input. The folder (for now, until we get it to work) has "Full Control" permissions for Everyone, ANONYMOUS LOGIN and Administrators users.
Andrew Harmel-Law
Procmon is the man if there's any confusion - that'll show you which principal is failing to get to do what it wants and where. Adding the admin users wont help. Typically the default app pools run as Network service. But you're far better off learning to fish in this case.
Ruben Bartelink
I take it from your desc of the problem that you have definitely hooked up the initialization as the normal logging is happening - you should keep two appenders configured to be sure that it's still just one that's failing.
Ruben Bartelink
Yup, it seems normal logging is fine. I'll try and find out using Procmon what's going on in Log4Net land...
Andrew Harmel-Law
... did you figure it out?
Ruben Bartelink
+1  A: 

I have also had to add this line to the AssemblyInfo.cs file of my application in order to get log4net working.

// LOG 4 net config
[assembly:log4net.Config.XmlConfigurator(Watch=true)]
Alex Preston
Surely normal logging wouldnt work then - he's proved that the config isnt the issue?
Ruben Bartelink
Note that you do have to specify this line in the project/dll where you are using log4net the first time. Therefore, I usually take no chances and just add it in all my assemblyInfo.cs's.
Ruben
which project do you specifically have to add this line as I have my service implementation in a different project, the WCF host in a different project and a separate project where I do Handle the error..
chugh97
You need to add it to the project where you call log4net for the first time.
Alex Preston
A: 

Do you have a configuration section configured for log4net? I didn't see that in your code snippet

chris166
A: 

I would first run the WCF service as a console application - this way you can specify the user account for the application to run as and see if the problem is with your config or with a permissions issue running the service through IIS.

If you are unsure of how to run the service as a console application take a look at http://www.jacopretorius.net/2009/08/running-windows-service-inside-console.html

Jaco Pretorius
A: 

Try XmlConfigurator.Configure()

User Friendly
A: 

I am facing the similar issue, running using log4net in W.C.F. service. It it because. Doesn't matter if services are run on self host