Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

485
Views
Why am I getting two log files per day using log4net with ASMX web service?

I have a ASMX web service running IIS 10 and have added log4net to the project with the following configuration:

<appender name="AsmxDebugLogFile" type="log4net.Appender.RollingFileAppender">
  <file value="App_Data/ASMX.DEBUG_" type="log4net.Util.PatternString" />
  <appendToFile value="true" />
  <rollingStyle value="Composite" />
  <datePattern value="yyyy-MM-dd'.log'" />
  <maximumFileSize value="5GB" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>
<logger name="AsmxDebugLogFile">
  <level value="DEBUG" />
  <appender-ref ref="AsmxDebugLogFile" />
</logger>

But for some reason, I'm getting two log files per day in the format of yyyy-MM-dd.log.yyyy-MM-dd.log as per the screenshot below, seemingly at random times as well, whereby the log file will switch to the newly created log file, and then will start logging again in the log file at was created at midnight of the day in question. All log files are way below the 5GB max file size as well.

Two log4net log files per day

Below is an updated list of log files

enter image description here

It seems that initially, log4net logs to the file yyyy-MM-dd.log, and then after a random amount of time creates a new log file yyyy-MM-dd.log.yyyy-MM-dd.log starts writing to this log file and then goes back and logs to yyyy-MM-dd.log which was created at the start of the day.

These are the IIS recycle settings

IIS Settings

I am wanting 1 log file per day in the format of ASMX.DEBUG_yyyy-MM-dd.log. Where am I going wrong with this configuration?

UPDATE

It seems that because we are recycling the application pool every 60 minutes depending on whether the log file is being written to at this time, depends on whether a new one is created. Any suggestions as to how to overcome this issue. At the minute I've now added the process_id in the log file name and it seems to work in that I get a new log file created every hour, but ideally I want just 1 log file a day.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I use log4net for all my applications and I never encountered this re-creation of file after a pool recycling.

Here are my parameter that differ from yours :

<appendToFile value="true"/>
<staticLogFileName value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>

And here's how the behaviour will be different :

  • staticLogFileName means current day's file name will always be the same (ASMX.DEBUG_.log here). It will be automatically renamed with the date pattern on the day after.
  • appendToFile means it will not overwrite current day's file, but rather append to it.

I think those first two parameters will avoid the creation of multiple file for the current day which may fix your problem.

  • MinimalLock's role is less clear to me, but I should mention it anyway :

Opens the file once for each AcquireLock()/ReleaseLock() cycle, thus holding the lock for the minimal amount of time. This method of locking is considerably slower than FileAppender. ExclusiveLock but allows other processes to move/delete the log file whilst logging continues.

over 4 years ago · Santiago Trujillo Report

0

<appender name="AsmxDebugLogFile" type="log4net.Appender.RollingFileAppender">
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>

I think you need Locking model which will not lock your file.I think when main file gets created and get locked. The File appender creates file name with same date time stamp over the exisiting file. You should also use Remote path for logging like \\server\file\debug since you might have load balancer for IIS or Web server is hosted with static IP or F5.

over 4 years ago · Santiago Trujillo Report

0

Try with this parameters.

  <param name="File" value="C:\YourLogFilePath\" />
  <rollingStyle value="Composite" />
  <param name="DatePattern" value="dd.MM.yyyy'.log'" />
  <param name="AppendToFile" value="true" />
  <maxSizeRollBackups value="2" />
  <maximumFileSize value="5GB" />
  <staticLogFileName value="false" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!