0

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 I'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
  • 1
    Did you remember to initialize it in code?
    – Kurt
    Commented May 6, 2010 at 12:33
  • if you mean private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(PostTradeRules)); where PostTradeRules is my class name, then I did...:) Commented May 6, 2010 at 13:09

3 Answers 3

3

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();

5
  • Jens, why exactly do I need to execute XmlConfigurator.Configure()? M asking because I genuinely dont have a clue. :) Commented May 6, 2010 at 13:11
  • One more note here Jens... i think m using an old version of VS which does not have XmlConfigurator. Can I use BasicConfigurator instead? Commented May 6, 2010 at 13:40
  • XmlConfigurator is a class of the log4net framework, has nothing to do with VS Commented May 6, 2010 at 14:17
  • oh ok...in that case, are you saying that i might be using an old version of the log4net.dll itself? Commented May 6, 2010 at 14:48
  • @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() Commented May 6, 2010 at 21:06
1

try writing:

<log4net debug="true">

it will post all errors to console.

3
  • Hi Andrey, where do I put this bit? Commented May 6, 2010 at 13:12
  • @Rishi Poptani what about googling a bit? logging.apache.org/log4net/release/example-apps.html don't be lazy
    – Andrey
    Commented May 6, 2010 at 13:39
  • @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
    Commented May 6, 2010 at 15:13
1

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.:)

Not the answer you're looking for? Browse other questions tagged or ask your own question.