Hi all,

After linking the master branch of log4net to my project and debugged it, the 
error vanished somehow.
Now it is also working with actual NuGet package 2.0.15.
I have no clue, as I see (but it is after midnight here) no difference in the 
app.config or anywhere else. The only thing I did in between was updating my 
Visual Studio 2022 and set the langiage to English.

Sorry to have bothered you, maybe I see tomorrow more clear!

So for now we can close the case on this!

BR
Peter

From: Wein, Peter
Sent: Wednesday, July 26, 2023 12:51 AM
To: 'log4net-user@logging.apache.org' 
<log4net-user@logging.apache.org<mailto:log4net-user@logging.apache.org>>
Subject: log4net RollingFileAppender seems to have an issue writing to 
LOCALAPPDATA folder or in General to hard code C: Pathes, in opposite to 
FileAppender, which works flawlessly

Hi all, I am new here, and hope for help, it might actually be, I found 
something like a bug or something!

In the end, it ended up that fileAppender and RollingFileAppender differs in 
data file placement rules. The one accesses easily places on C the other not.

My System:

-          Windows 10
[cid:image001.png@01D9BF74.095F1C80]
[cid:image002.png@01D9BF74.095F1C80]

-          .Net 6 Framework

-          Visual Studio 2022

I was configuring a small example project with Log4Net. I followed the Tim 
Corey Example here:
https://www.youtube.com/watch?v=2lAdQ_QwNww

but also I used your very similar and even more simple example in your example 
code for .Net 2.0, c#.

I ran every time into the same issues:
FileAppender seems to work with this configuration:
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file type="log4net.Util.PatternString" 
value="${LOCALAPPDATA}\Temp\ProgramX\log.log"/>
      <encoding value="utf-8" />
    <!--  <datePattern value="yyyy-MM-dd'-log.txt'" />  -->
      <appendToFile value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%logger] %level - 
%message%newline%exception" />
      </layout>
</appender>

And writes it for example here in LOCALAPPDATA or to my personal documents 
folder on C: drive.

RollingFileAppender misses that and just didn't do nothing  (taken from your 
example with very simple config, mine was a little extended):
    <appender name="file" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="log_rolling.txt"/>
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="25MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger.%method[%line] 
- %message%newline" />
      </layout>
    </appender>

Even with a place directly to an externally SSD, it works:
    <appender name="file" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="E:\log_rolling.txt"/>
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="25MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger.%method[%line] 
- %message%newline" />
      </layout>
</appender>

And finally I was able to work out my example with the date (where is the 
documentation on "App.config log4net rules" btw. It was a bit hairy to find it 
out (most of the way many stackoverflow solutions):
    <appender name="file" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" 
value="E:\%date{yyyyMMdd}_log_rolling_file.log"/>
      <encoding value="utf-8" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <maxSizeRollBackups value="100" />
      <maximumFileSize value="25MB" />
      <preserveLogFileNameExtension value="true" />
      <staticLogFileName value="false" />
      <datePattern value="_yyyyMMdd'.log'" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger.%method[%line] 
- %message%newline" />
      </layout>
</appender>
So now it prints the date at the beginning because of my filename and at the 
end(because of the datePattern). I will prefer the filename extension at the 
beginning, cause then you can sort acc. to date!

But my main problem to be reported here is:

Why are FileAppender and RollingFileAppender act so differently because of the 
file placement? I need to roll out in my company without knowing each specific 
access rights resolution. So I guess there must be a little difference in 
handling these two Appender Types.

Please help!

Thanks in advance
Peter

-----
KOSTAL Automobil Elektrik GmbH & Co. KG - Sitz Lüdenscheid, Registergericht 
Iserlohn HRA 2854, phG Kostal Verwaltungsgesellschaft mbH, Wien, Österreich – 
Handelsgericht Wien FN 494989 a - USt-Id-Nr./Vat No.: DE 125800885

Post- und Werksanschrift: An der Bellmerei 10, D-58513 Lüdenscheid * Telefon: 
+49 2351 16-0 * Telefax: +49 2351 16-2400 Bellmerei

Geschäftsführung: Dipl.-Ing. Kai Knickmann (Vorsitzender), Dr.-Ing. Tino 
Naumann, Dipl.-Ing. Jörg Schwerak, Dipl.-Ing. Hansjörg Herrmann


The information contained in this email and any attachment herein is strictly 
confidential.

It is exclusively addressed to the intended addressee(s). If you are not an 
intended addressee, any review, use, disclosure, reproduction, distribution or 
other dissemination of this information is strictly prohibited. If you have 
received this e-mail by mistake, please notify the sender and delete this 
e-mail and the information contained herein immediately.


In the case of a first contact by email, we are obliged to provide you with the 
following mandatory information in accordance with Art. 12, 13 GDPR. If you 
contact us by email, we will process your contact data and information on your 
request for the purpose of processing your request. You are not obliged to 
provide this data. Without this data, however, we cannot process your request 
properly. If you contact us as an interested party or customer, we process the 
data for the purpose of carrying out pre-contractual measures at your request 
or for the execution of a contract with you (Art. 6 para. 1 sentence 1 lit. b 
GDPR). In addition, the legal basis for this processing is the balancing of 
interests (Art. 6 para. 1 sentence 1 lit. f GDPR). In this case, our legitimate 
interest is to process the request you have communicated. If you have given 
your consent to data processing (Art. 6 para. 1 sentence 1 lit. a GDPR), we 
will process the data on the basis of this consent. You can revoke this consent 
at any time at datensch...@kostal.com. We will store this data for the duration 
of processing your request and thereafter for the duration of the statutory 
storage obligations (Art. 6. Para. 1 sentence 1 lit. c GDPR). You can find 
further information at https://www.kostal.com/en-gb/datenschutz.

Reply via email to