Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

493
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda