config有了一个类库

config有了一个类库

本文介绍了.NET - 存储一个app.config有了一个类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是问了很多在互联网上,但到目前为止,我的研究还没有产生一个解决方案。 (而且,至少在目前,我还没有接受不能做作为解决方案。)

This seems to be asked a lot on the internet, but so far my research hasn't produced a solution. (And, at least for now, I haven't accepted "it can't be done" as a solution.)

目前最简单的描述,我想要做的是有一个.NET类库项目,可供该类库引用它的任何应用程序的配置文件。我的设置可以简化为3 WCF服务分享一些领域逻辑。其中一个他们共同的东西是一个记录器注入依赖。在这种情况下,我有一个实现记录器的单独库(这个库是被注射),使用log4net的。

At its simplest description, what I'm trying to do is have a config file in a .NET class library project that is available to that class library in any application that references it. My setup can be simplified to 3 WCF services sharing some domain logic. One of the things they share is an injected dependency of a logger. In this case I have a separate library that implements the logger (this library is what gets injected) using log4net.

在此设置中,每3个服务都有自己的配置文件,其中每个配置文件,需要配置log4net的。我正在试图做的是完全抽象的log4net到独立的库,使这3个服务(以及未来的服务/应用程序,其中会有很多)不必进行该配置。他们都将被以同样的方式配置,所以我宁愿它是在一个地方。

In this setup, each of the 3 services has its own config file and each of those config files needs to configure log4net. What I'm trying to do is fully abstract log4net into the separate library so that these 3 services (and future services/applications, of which there will be many) don't have to carry that configuration. They're all going to be configured the same way, so I'd rather it be in one place.

到目前为止,我已经成功地找到了一些code,使appsetttings(键/值对)库本地化的配置文件,我可以访问。但是我正在寻找一个更完整的配置文件的方法。 log4net的有自定义配置节这比键/值对。 (其他的配置部分也将会在多个应用程序,如在所使用的客户端应用程序的公共库system.serviceModel部要用来连接到WCF服务)。

So far I've managed to find some code that will allow a library-localized config file of appsetttings (key/value pairs) and I can access that. But I'm looking for a more complete config file approach. Log4net has a custom configuration section that's more than key/value pairs. (Other config sections are also going to be used across multiple applications, such as the system.serviceModel section in a common library used by client applications to connect to the WCF services).

这是否有道理?有没有人想出了一个解决方案,这种事情之前?

Does this make sense? Has anybody come up with a solution to this kind of thing before?

推荐答案

您真的不能以同样的方式为可执行文件与一个类库.config文件!然而,一个类库当然可以读写XML文件,这样你就可以伪造它在一定程度上。 code项目本文介绍这样做的一种方法,我也不会,如果有其他类似的解决方案,因为正如你所说,这是一个常见的​​问题感到惊讶。

You really can't have .config files with a class library in the same way as for executables! However, a class library can of course read and write xml files so you can fake it to a certain extent. This code project article describes one way of doing it, I wouldn't be surprised if there are other similar solutions, since as you say, it's a common question.

这篇关于.NET - 存储一个app.config有了一个类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:21