Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4Net and .NET 4.0

Tags:

.net

log4net

There have not been any log4net release for some time. This has not presented any problems with 3.5, but what about .NET 4? Has anyone heard any rumblings about a release to support the version 4 framework when it comes out?

like image 554
Bobbie Avatar asked Dec 08 '09 12:12

Bobbie


People also ask

Is log4net compatible with .NET 5?

log4net works with almost any version of . NET (including . NET Core).

Does log4net support .NET Core 6?

Log4Net targets . NET Standard, which gives it a level of compatibility across the entirety of . NET core, including . NET 6.


1 Answers

"With .NET 4. Projects you can still use log4net. You will have to change the target platform to ".NET Framework 4" on the project..."

Is correct. But you need to put the line

<startup>    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> 

to the bottom of the configuration file (after the log4net setup):

<?xml version="1.0"?> <configuration>   <configSections>     <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />   </configSections>   <log4net>     <appender name="FileAppender" type="log4net.Appender.FileAppender">       <file value="logfile.txt" />       <appendToFile value="true" />       <layout type="log4net.Layout.PatternLayout">         <conversionPattern value="%date: %-5level – %message%newline" />       </layout>     </appender>     <root>       <level value="DEBUG" />       <appender-ref ref="FileAppender" />     </root>   </log4net>   <startup>     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>   </startup> </configuration> 

Tested with log4net 1.2.10.0 You need to put the line: [assembly: log4net.Config.XmlConfigurator(Watch = false)] in Assemblyinfo.cs (I forgot that)

like image 142
Gryffe Avatar answered Oct 04 '22 08:10

Gryffe