C# application which is executed with .NETFramework 4.7.2.
We have been using log4net for several years now and have always been satisfied. Unfortunately, since version 2.0.12 we have been having problems with the log not being written. When I delete the old log file, a new file is created, but no log entries are added to the file.
Here is the entry in the App.config:
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="Log\WMS4_Server_Log.xml" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j">
<locationInfo value="true" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
Can anyone give us a hint as to why this might be?
I have added the following entry in the Main() method as suggested:
log4net.Config.XmlConfigurator.Configure();
That helped for a while, but now we have the same problem again. We are now ready to replace log4net with another logger if there is no remedy. I also enabled the internal logging but didn't get any hint.
The following shows how one can use Nuget package log4Net to write to a log file. It's been tested with Nuget package log4Net (v2.0.15). While the code below does write to the log file, I'm not all that familiar with log4net, so you may have to modify the code below to get the output in the desired format.
Note: The following will write to log file: %ProgramData%\log4netTest\Logs\log.xml. Also, you'll notice that I've used .NET Framework v4.8 for the test, so change the value as necessary.
App.config:
Here's a test project that logs the current time every 5 seconds. To re-create the test project I used:
Create a Windows Forms App (.NET Framework) (name: log4netTest)
Add two buttons to Form1
Note: In the form designer, double-click each button to add the Click event handler.
Form1.cs:
Resources: