简体   繁体   English

解决方案中的log4net和多个启动项目

[英]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. Project Vis和Project Test都可以充当启动项目,或者Project Test可以作为独立于Project Vis之外的过程来启动。 They both focus on a class library Project Calc. 他们俩都专注于类库Project Calc。 So, if I test Project Calc with Project Test then log4net works fine. 因此,如果我使用Project Test测试Project Calc,则log4net可以正常工作。 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. 但是,如果我使用Project Vis(仍是VS2010中的Visual Studio插件)作为启动程序,然后启动Project Test来测试Project Calc,则会遇到问题。

Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. 无法加载文件或程序集'log4net,版本= 1.2.13.0,文化=中性,PublicKeyToken = 669e0ddf0bb1aa2a'或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。

This is thrown from the Constructor for a class in Project Calc. 这是从构造函数中为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: 对于Project Calc中的代码,内部配置略有不同,我们使用CodeDom来构建一些C#文件并将其编译为Project C使用的单独的dll(请参见此处的aevitas回答),我收到了:

System.TypeInitializationException was unhandled Message: The type initializer for 'Test' threw an exception. System.TypeInitializationException未处理消息:“测试”的类型初始值设定项引发了异常。

I think this is also related to the log4net implementation. 我认为这也与log4net的实现有关。

I have links to the external log4net config file in all the projects, and the following line once in each project: 我在所有项目中都有指向外部log4net配置文件的链接,每个项目中都有以下行一次:

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

and the following line once in each class from whence I call the log methods: 并在每个类的下一行中调用一次log方法:

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? 那么问题可能是因为已经用log4net配置了Project Vis,然后启动了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.) (也就是说,Project T也可以单独执行以测试Project Calc。)

It seems your log4net dll is not copied to your bin directory. 看来您的log4net dll没有复制到您的bin目录中。 Check if the dll is there and if not configure your project to copy it to your bin directory. 检查dll是否存在,以及是否未配置项目以将其复制到bin目录。 You can easily test this by copying the log4net dll by hand into your bin directory when running as addin. 您可以通过将log4net dll作为外接程序运行时手动将log4net dll复制到bin目录中来轻松进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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