tags:

views:

112

answers:

1

Hi Everyone,

I'm facing a problem when trying to log my application using log4net. My application consists of a WCF service, and clients connecting to it. Logging at client-side is not a problem, everything works perfectly.

Here is how my server-side is made:

  • A WCF dll, which contains my service's contract and base implementation (including error handling). Actual operations are made in a separate business layer, which throws the needed exceptions which are caught by the implementation (and sent back using FaultContracts).
  • A data layer (not a problem here).
  • A "Utils" library, which contains my wrapper log methods.

My log4net.config file is the following:

<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false">

  <appender name="TechnicalFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
    <param name="File" value="c:\\log\\technical.log"/>
    <param name="AppendToFile" value="true"/>
    <param name="RollingStyle" value="Date"/>
    <param name="DatePattern" value="'_'yyyyMMdd-HH"/>
    <layout type="log4net.Layout.PatternLayout,log4net">
      <param name="ConversionPattern" value="%d [%-5t] %-5p - %m%n"/>
    </layout>
  </appender>

  <root>
    <level value="ALL"/>
  </root>

  <logger name="TechnicalLog">
    <level value="ALL"/>
    <appender-ref ref="TechnicalFileAppender"/>
  </logger>

</log4net>

So when an error occurs in the business layer, it is captured, logged and transformed into a FaultException. There is the problem. No log file is created. I googled and found some clues (access rights generally, but I used ProcMon and found no call to the desired file or directory).

I'm a bit lost now, I don't know what to try.

I publish my service using the "publish" command in visual studio, so on the server I have my application directory, inside there is a svc file, a web.config file, and then a bin directory with all my dll's including the log4net.dll, and log4net.config. I tried to copy that config file in the root of my application without success.

I also tried to place the [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)] statement in my WCF's AssemblyInfo.cs (it was originally in the Utils's AssemblyInfo.cs), but without any success.

Thanks for you help, any idea is welcome !

A: 

I am pretty sure that log4net does not find the configuration file.

I had the same issue and I think I solved it by having an application setting in the web.config file that contains the full path to the log4net config file. In my wrapper I made sure that log4net is configured by calling the ConfigureAndWatch method if log4net is not configured yet.

Alternatively you could simply copy the log4net configuration to the web.config file (but I would not do that because you loose the ability to change the log settings for the running system). In that case you need to add this to you AssemblyInfo.cs (or some other file if you prefer):

[assembly: log4net.Config.XmlConfigurator()]

If that still does not help then I recommend to turn on internal debugging.

Stefan Egli
Hi Stefan, thanks for your answer. I tried your last proposition (placing the config in the web.config), but without success... I removed all the "assembly" entries from AssemblyInfo files, but it doesn't change anything... Am I missing something ?
Shimrod
See my revised answer. If you have the configuration in the web.config you still need to tell log4net to load it. Sorry that was not explained clear enough.
Stefan Egli
It is still not working... I also tried hardcoding the path to the config file and use the ConfigureAndWatch, but I get an access denied exception (SecurityException)... Which is really strange, as it is in the same directory as the application.
Shimrod