将App.config应用到我的DLL程序集? [英] Apply an App.config to my DLL assembly?
问题描述
配置设计要指定以下内容:
- 要写的日志记录级别
- 写入所有级别的一个日志文件
- 每级写入单独的文件
- 记录截止(定期,应用程序事件,字节大小限制) / li>
- 日志文件过期(删除文件记录后的日志文件)
- 以平面文本或XML形式写入
- 日志文件名格式说明
- 是否为文件名前缀日期
- 父应用程序名称
- 等,等等...
我已经阅读了关于DLL程序集的配置的一些其他stackoverflow问题,并导致app.config之间的冲突主机程序集/应用程序我相信我的程序集只是提供一个配置文件。
这是一个很好的场景吗?将我自己的配置烘烤到我的项目中可能是一个更好的主意,以便我的记录器从XML文件读取以检索配置值?
p>您可以做的是
-
创建自定义配置部分(使用例如配置部分设计器工具)
-
将程序集的配置放在一个单独的
MyAssembly.config
文件 -
从您的主机应用程序的配置中引用该程序集配置文件:
< configuration>
< configSections>
< section name =YourAssembly
type =YourAssembly.ConfigSection,YourAssembly/>
< / configSections>
< YourAssembly configSource =MyAssembly.config/>
< / configuration>
这样,你可以外化你的配置到一个单独的配置文件,您只有一次(在程序集的项目中),任何需要它的项目只需要在自己的配置文件中的这些设置。
I'm writing a class library as an abstraction to use for logging in any application, service, etc. that I write. I'm making it decently robust by making it very configurable to suit my needs for most application/service logging scenarios that I come across.
The config is designed to specify things such as:
- What logging level to write
- Write to one log file for all levels
- Write to separate files per level
- Logging cutoff (periodic, app event, byte size restricted)
- Log file expiration (delete log files after file age)
- Write as flat text or XML
- Log file name format specification
- Whether to prefix filename with date
- Parent app's name
- etc, etc, etc...
I've read some other stackoverflow questions regarding configs for DLL assemblies and it causing conflict between the app.config for the hosting assembly/app. I believe that my assembly has just cause to provide a config file.
Is this a good scenario for that occasion? Is it perhaps a better idea to bake my own config into my project so that my logger reads from XML files to retrieve config values?
What you could do is
create a custom configuration section (using e.g. the COnfiguration Section Designer tool)
put your assembly's configuration into a separate
MyAssembly.config
filereference that assembly config file from your host app's config:
<configuration> <configSections> <section name="YourAssembly" type="YourAssembly.ConfigSection, YourAssembly" /> </configSections> <YourAssembly configSource="MyAssembly.config" /> </configuration>
That way, you can "externalize" your configuration into a separate config file which you have only once (in your assembly's project), and any project needing it just needs those settings in its own config file.
这篇关于将App.config应用到我的DLL程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!