views:

349

answers:

3

Hi Guys, I'm using log4net v1.2 with a Windows Service App. My RollingFileAppender seems not to work. I'm pasting the logging sections of my service.exe.config below. Can anyone advise where m going wrong?

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>

.....(lots of other config stuff)

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender,log4net" >
            <param name="File" value="D:\\Trinity\\Booking\\OneDay_PostTrade\\logs\\Trinity.log" />
            <param name="MaximumFileSize" value="20MB" />
            <param name="MaxSizeRollBackups" value="10" />
            <param name="StaticLogFileName" value="true" />
            <param name="Threshold" value="ALL" />
            <param name="RollingStyle" value="Composite" />
            <param name="appendToFile" value="true" />
            <layout type="log4net.Layout.PatternLayout,log4net">
                <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
            </layout>
        </appender>

...(stuff in between)

<root>
        <level value="ALL" />
          <appender-ref ref="ConsoleAppender" />
          <appender-ref ref="RollingFileAppender" />
      </root>

.....(stuff in between)

<logger name="CSFB.PostTradeRulesEngine">
            <level value="ALL"/>        
            </logger>   
+2  A: 

The user your windows service is running as might not have write permission for the log file.
Another possibility is that you forgot to execute XmlConfigurator.Configure();

Jens Granlund
Jens, why exactly do I need to execute XmlConfigurator.Configure()? M asking because I genuinely dont have a clue. :)
Rishi Poptani
One more note here Jens... i think m using an old version of VS which does not have XmlConfigurator. Can I use BasicConfigurator instead?
Rishi Poptani
XmlConfigurator is a class of the log4net framework, has nothing to do with VS
Stefan Egli
oh ok...in that case, are you saying that i might be using an old version of the log4net.dll itself?
Rishi Poptani
@Rishi, my bad, the XmlConfigurator was introduced in v. 1.2.9. If you´r using a earlier version this should do the trick: DOMConfigurator.Configure()
Jens Granlund
A: 

try writing:

<log4net debug="true">

it will post all errors to console.

Andrey
Hi Andrey, where do I put this bit?
Rishi Poptani
@Rishi Poptani what about googling a bit? http://logging.apache.org/log4net/release/example-apps.html don't be lazy
Andrey
Hey Andrey, I took both your pieces of advice...:)Still, doesn't work..
Rishi Poptani
@Rishi Poptani what doesn't work? download and run samples from link. do they work? and about <log4net debug="true"> it will not solve your problem but it will output errors to console so that you can analyze and fix them
Andrey
The change you suggested is not outputting errors to console...
Rishi Poptani
A: 

Hey guys, thanks to everyone who responded. I dont know what i changed but my logging has started working fine.

Posting my logging sections. I didnt change anything in the code, except a line in the AssemblyInfo.cs: [assembly: log4net.Config.Domain(UseDefaultDomain=true)]

Thanks again.:)

Rishi Poptani