简体   繁体   中英

log4net and multiple start-up projects in solution

We have many projects in the solution, and quite a few projects that act as test projects for certain of the class library projects. Project Vis and Project Test can both act as start-up projects, or Project Test can be started as a separate process from out of Project Vis. They both focus on a class library Project Calc. So, if I test Project Calc with Project Test then log4net works fine. However, if I use Project Vis (which is a Visual Studio addin still in VS2010) as the start-up, and then launch Project Test to test Project Calc, I hit problems.

Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The system cannot find the file specified.

This is thrown from the Constructor for a class in Project Calc.

With a slightly different internal configuration for code in Project Calc in which we use CodeDom to build some C# files and to compile it into a seperate dll that Project C uses (look at the aevitas answer here ), I have received:

System.TypeInitializationException was unhandled Message: The type initializer for 'Test' threw an exception.

I think this is also related to the log4net implementation.

I have links to the external log4net config file in all the projects, and the following line once in each project:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4NetSettingsGlobal.xml", Watch = true)]

and the following line once in each class from whence I call the log methods:

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

So could the problem be because of having Project Vis already configured with log4net and then starting Project T? How could I work around this, so that I can accommodate both scenario's? (That is, Project T also being executed on its own to test Project Calc.)

It seems your log4net dll is not copied to your bin directory. Check if the dll is there and if not configure your project to copy it to your bin directory. You can easily test this by copying the log4net dll by hand into your bin directory when running as addin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM