0

Following is the appender written in log4net's configuration file

<appender name="RollingFileAppenderForError" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="D:\WEB\LOGs\%date{yyyyMMdd}\"/>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
    <appendToFile value="true"/>
    <rollingStyle value="Composite"/>
    <datePattern value="lo\gs_yyyyMMdd.lo\g"/>
    <maxSizeRollBackups value="50"/>
    <maximumFileSize value="1MB"/>
    <staticLogFileName value="false"/>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="[%date{yyyy-MM-dd HH:mm:ss, fff}]  [%property{ServiceTxnID}]  [%property{TxnRequestID}]  %-5level %logger{2} %ndc - %newline Exception: %message - %exception %newline "/>
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="DEBUG" />
        <levelMax value="FATAL" />
    </filter>
</appender>

Here the problem is, in local and QA environment log4net is writing the log file in correct folder (New folder created everyday) but in production environment its writing the log file in wrong folder let say

In the folder for day 20130706 (YYYYMMDD) its writing the files of logs_20130706.log and logs_20130707.log. and in folder 20130707 we can see the files logs_20130707.log and logs_20130708.log.

I could not get the problem exactly where we are doing a mistake. Will be great if anyone can help me in this.

Philipp M
  • 1,877
  • 7
  • 27
  • 38
Sandeep Kumar
  • 783
  • 1
  • 5
  • 13

1 Answers1

0

I guess the file type attribute is not re-calculated as often as the datePattern, you can try this:

<appender name="RollingFileAppenderForError" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="D:\WEB\LOGs"/>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
    <appendToFile value="true"/>
    <rollingStyle value="Composite"/>
    <datePattern value="yyyyMMdd\\\\'logs_'yyyyMMdd'.log'"/>
....
</appender>
Dmitrii Dovgopolyi
  • 6,231
  • 2
  • 27
  • 44
Peter
  • 27,590
  • 8
  • 64
  • 84
  • I am not sure if this is the problem because log4net is writing the file in good folder only 1 file we found with next day's date – Sandeep Kumar Jul 08 '13 at 09:11
  • I applied these settings in my local environment. I changed in `` system prepare the file `20130715Error_20130715.log` So every change we made in `datePattern` it reflects in file name not in directory. Which indicates folder name can be calcuated in ` – Sandeep Kumar Jul 15 '13 at 06:52