Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with Log4net. Running C# .Net 4.7.2, Log4Net Ver. 2.0.13.

I want to have a new file

for every new day (so I set rollingStyle to 'Date')
if max size is exceeeded (so I set maximumFileSize to '10MB')
if program is started again (so I set appendToFile to 'false')
for every other user (so I use the USERNAME in the filename)

And I want to have the second generated file with a new filename, so first generated logfile wouldn't be renamed (because program could be opened twice, so first filename shouldn't be changed).

So I would expect the following filenames:

first program call: programname_user_301221.0.log
second program call: programname_user_301221.1.log
third program call: programname_user_301221.2.log


I'm using the following RollingFileAppender:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="programname_${USERNAME}_">
<datepattern value="ddMMyy'.log'">
<staticlogfilename value="false">
<preservelogfilenameextension value="true">
<countdirection value="1">
<appendtofile value="false">
<rollingstyle value="Date">
<maxsizerollbackups value="5">
<maximumfilesize value="10MB">
<layout type="log4net.Layout.PatternLayout">
<conversionpattern value="%date{dd.MM.yyyy HH:mm:ss} %-5level %-5thread %message%newline">




With this configuration, there are two problems: When starting program, I get correctly the file "programname_user_301221.0.log"

1) When closing program and starting it again, there is no new file generated, but existing file is overwritten!
2) When starting program a second time (and first time is still running) I get correctly a second file, but with a wrong filename "programname_user_301221.0301221.log.0.log"

What I have tried:

Different changes in the RollingFileAppender
Posted
Comments
[no name] 3-Jan-22 11:35am    
You're fiddling with file names; one would think there should be a cleaner way to get "generations".
Member 11168540 4-Jan-22 2:16am    
Hello Gerry,
what would you suggest?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900