views:

901

answers:

6

I have a windows service that uses log4net. We noticed that the service in question was running painfully slow so we attached a debugger to it and stepped through. It appears that each time it tries to write an entry to the log via log4net that it takes anywhere from 10 to 30 seconds before the next line of code can execute. Obviously this adds up...

The service is 2.0 .net We're using log4Net 1.2.0.30714. We've tested this on a machine running vista and a machine running win sever 2003 and have seen the same or similar results.

+1  A: 

Jeff mentioned a performance problem with Log4Net in Podcast 20. It's possible that you are seeing a similar issue.

Greg Hewgill
A: 

I have log4net with adonet appender and have not seen any decremental performance of my windows service. what appender are you using?

A: 

Check your config file for Log4Net settings. Log4Net can be configured to log to a remote machine, and if the connection is slow, so will be your logging speed.

MusiGenesis
A: 

Well I'm not remoting... this is writing to the log file on the machine it's running on. Here's my appender settings:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <file value="D:\\ROPLogFiles\\FileProcessor.txt" />
      <appendToFile value="true" />
      <datePattern value="yyyyMMdd" />
      <rollingStyle value="Date" />
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
      <threshold value="INFO" />
    </appender>
A: 

the default maximum file size is 10mb . if your files are about this size and your file systems is quite full and probably heavily fragmented, it may be possible that the problem lies there. how big are your log files? i encountered similar problems with logfiles at gigabyte size.

Joachim Kerschbaumer
+1  A: 

It turned out that someone had added an SMPTAppender in a config file which was overriding the one in our app. As a result the errant SMPT server address was unreachable. log4net was trying to log the error for a minute per request and then giving up and going on to the next line of code. Correcting the smtp address fixed the problem.

It could be a good idea to have a separate process or thread to send SMTP mails, otherwise you're still blocking for a TCP round-trip on each message logged - and if the SMTP server is down, you'll have the same problem again.
orip