Sunday, September 18, 2011

UPDATED: Getting Log4Net to work with Dot.Net Framework 4.0

 

UPDATED: If you want to write code for Log4Net and you’re using dot.net 4 and it won’t compile do the following

open the src directory and open the log4net.csproj –> update it to dot.net 4

  1. Project Properties :
    1. Application : Target Framework : .Net Framework 4
      image
    2. Build : Conditional compilation symbols: change NET_1_0 to NET_4_0
      image
  2. AssemblyInfo.cs

Line 52: copy the line 52 and 53

and paste it under line 52

change #elseif(NET_1_0) to #elseif(NET_4_0)

and change Framework 1.0 to Framework 4.0

image

3. in References: Delete System.Data, System.Web references and add Reference : System.Data and System.Web from the .NET tab

*this is don’t so they are Framework 4 compatible (before they were Framework 1.1 compatible, which is not good enough for Framework 4.0 I guess.

Now change The SystemInfo CurrentThreadId from the Obsolete GetCurrentThreadId to the new System.Threading.Thread.CurrentThread.ManagedThreadId;

image

 

Next

Some security changes were made in the .NET 4.0 framework. In the AssemblyInfo.cs file of the log4net project, you'll find the following line:
[assembly: System.Security.AllowPartiallyTrustedCallers] –

This is affected by the security changes. Take a look at this page for more details: http://msdn.microsoft.com/en-us/library/system.security.allowpartiallytrustedcallersattribute.aspx.

because it’s bad for dot.net 4 , but not for anything else

add

image

 

Now Build using Release and all should work.

good luck

No comments: