2

We are planning to use Log4net in our application . But I am unable to import the "log4net" namespace if the target framework is 4.

I also get a warning The referenced assembly "log4net" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

So what is going wrong here ?

Note-Logging works if I change the target framework to 3.5 Note-This is a windows application .

Thanks in Advance.

Ananth
  • 10,330
  • 24
  • 82
  • 109

5 Answers5

8

On the projects properties page change the target framework from .NET Framework 4 Client Profile to .NET Framework 4

scott
  • 2,991
  • 5
  • 36
  • 47
3

See here for your answer:

log4net with .NET 4.0

Community
  • 1
  • 1
Jerod Venema
  • 44,124
  • 5
  • 66
  • 109
1

Please see this SO post: Log4Net and .NET 4.0

It has an answer that points to a solution here: http://krishnabhargav.blogspot.com/2010/02/using-net-35-clr-20-dll-inside-visual.html

Community
  • 1
  • 1
Adam Spicer
  • 2,703
  • 25
  • 37
1

Why are you not planning to use Nlog? It supports all latest .NET builds and isn't worse then log4net (even better for me).

Chingiz Musayev
  • 2,832
  • 1
  • 14
  • 6
0

If you are still getting the "Unable to find assembly references that are compatible with the target framework '.NETFramework,Version=v4.0'" when trying to install log4net even though your framework is pointing to 4.0, you probably need to update NuGet.

To do this, close your Visual Studio and reopen it as administrator. Tools > Extension Manager > NuGet Package Manager > Uninstall.

You will probably need to restart VS.

When it starts back up, go Tools > Extension Manager > Online Gallery and find Nuget there and install it.

You should then be able to install log4net properly.

ScubaSteve
  • 7,724
  • 8
  • 52
  • 65