0

We have old application that is single threaded and we run it multiple instances of it. I have noticed that it creates multiple logs with strange naming.

PASManifest-EDWWhatIfDbg.20180918-17.log PASManifest-EDWWhatIfDbg.20180918-17.20180918-17.log.log PASManifest-EDWWhatIfDbg.20180918-17.20180918-17.20180918-17.log.log.log Problem is, we have programs that reuse those logs and they are very sensitive to the log names. Is there a way to configure log4net, such that it only creates & uses PASManifest-EDWWhatIfDbg.20180918-17.log

  <appender name="EDWWhatIfDebugFile" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString">
    <conversionPattern value="D:\centralAM\Logs\EDWWhatIf\PASManifest-EDWWhatIfDbg"/>
  </file>
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <appendToFile value="true" />
  <preserveLogFileNameExtension value="true" />
  <staticLogFileName value="false" />
  <rollingStyle value="Date" />
  <datePattern value="'.'yyyyMMdd-HH'.log'" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%5thread] %-5level %type{1}.%method() - %message%newline%exception" />
  </layout>
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="DEBUG" />
    <levelMax value="DEBUG" />
  </filter>
</appender>
newprint
  • 6,936
  • 13
  • 67
  • 109
  • 1
    if you run several instances of your application and all are configured to use the same log file name, only the first instance will be able to write to the configured log file name. log4net then likely falls back to adding another ".log" extension to the log file name and logs in there. Depending on how many instances you're running you may see a larger number of log files with that name pattern. – Dirk Trilsbeek Sep 19 '18 at 07:40
  • @DirkTrilsbeek This is exactly what happens ! – newprint Sep 19 '18 at 14:24
  • you have several options here, here is a good answer on SO about them: https://stackoverflow.com/questions/5728219/logging-multiple-instance-application-best-practice – Dirk Trilsbeek Sep 20 '18 at 06:26

1 Answers1

1

I suspect that the preserveLogFileNameExtension setting interferes with your date pattern. I suggest that you move the file extension to the file property. For instance like this:

<file value="D:\centralAM\Logs\EDWWhatIf\PASManifest-EDWWhatIfDbg" />
<datePattern value="yyyyMMdd-HH" />
<staticLogFileName value="false" />

Not 100% sure if it is going to work as I did not test it.

Stefan Egli
  • 17,398
  • 3
  • 54
  • 75