Do client applications still need to reference Log4Net if using Castle LoggingFacility?

StackOverflow https://stackoverflow.com/questions/13592160

  •  02-12-2021
  •  | 
  •  

Question

The reason I ask this is if the log4net.dll is not in the GAC and not in the current Executing Assembly directory, castle Logging facility will not find it.

I have built a class library that is going to be used by multiple client applications to do logging using Castle and Windsor, I have noticed that I don't need a reference to the log4net.dll in my class library at all, it just needs to be able to see the dll at runtime.

So I am just wondering where the reference should truly be because if I put in my class library it is not copied over to clients even though copy local is true, I think because it actually is never used directly.

Était-ce utile?

La solution

You definitely need to provide log4net.dll to get Castle logging facility to work (assuming you have configured the logging facility to use log4net). You are correct that you no longer need to reference log4net directly in your projects, because you will now be using Castle.Core's ILogger interface to actually write log messages. Your application still depends on log4net, albeit indirectly.

Visual studio normally handles these kinds of "indirect" references (A depends on B depends on C) properly (it copies C over to A's output directory). However, it does not copy the indirect reference (it does not copy C to A's output directory) when C is in the GAC on the machine performing the build.

My guess is that you have log4net.dll GAC'd on your development machine.

To resolve this, you either need to remove log4net.dll from your GAC (and from the GAC on any machine where you'll be building the app), or you must explicitly reference log4net.dll in your top-level executable (project A in the example above) and set "copy local" to true. This forces the compiler to copy the dll to the output directory.

This issue was also discussed in this SO question

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top