30

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?

Bobbie
  • 339
  • 1
  • 3
  • 4

7 Answers7

12

"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)

Gryffe
  • 121
  • 1
  • 3
  • 1
    +1 for including the info about adding the line to AssemblyInfo.cs. Otherwise, the log4net settings in the app config file will just be ignored. – Mun May 18 '12 at 14:28
8

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

More details.... http://krishnabhargav.blogspot.com/2010/02/using-net-35-clr-20-dll-inside-visual.html

krishna
  • 174
  • 1
  • 3
4

There is an issue in the tracking system for 4.0 support.
If you need it, you can compile the version yourself with the latest release - it will compile.

weismat
  • 7,195
  • 3
  • 43
  • 58
2

Here are our notes about getting log4net working with VS2010 with C# and .Net 4.0. It basically follows the tseonet post but in a few simple steps. We also set security level to 1 instead of commenting AllowPartiallyTrustedCallers, but either option appears to work.

Hope this is useful to someone: http://www.charlestonsw.com/configuring-log4net-with-vs2010-and-net-4-0/

Lance Cleveland
  • 3,098
  • 1
  • 33
  • 36
0

It seems that the current log4net trunk supports the .NET Framework 4.0. This support has just not yet been shipped with a release.

Nachbars Lumpi
  • 2,688
  • 1
  • 21
  • 13
0

There is a JIRA entry for .NET 4.0 and Client Profiles () but it is not slated for release in 1.2.11.

There is a related (unanswered) question with a comment that suggested you can simple run the 1.2.10 source through the VS2010 upgrade process.

Community
  • 1
  • 1
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
  • Thanks, that JIRA entry includes a patch - apply it on the SVN HEAD and then: "...To target .Net 4.0 define NET;NET_2_0;NET_4_0, To target .Net 4.0 Client profile append ;NET_CLIENT_PROFILE to the previous define." - that solved it for me (also, this patch now IS stated for release in 1.2.11, for future reference) – sinelaw Jul 27 '11 at 06:01
0

i work with log4net in my asp.net Web Application and no problem.

i work by this tutorial: http://www.codeproject.com/KB/trace/Log4Net_with_ASP_NET.aspx