将App.config应用于我的DLL程序集? [英] Apply an App.config to my DLL assembly?

查看:209
本文介绍了将App.config应用于我的DLL程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个类库作为一个抽象,用于登录我写的任何应用程序,服务等。我通过使其非常可配置,以适应我遇到的大多数应用程序/服务日志记录场景的需要,使它非常健壮。

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.

指定以下内容:


  • 要记录的日志级别


  • 记录截止(周期性,应用事件,字节大小受限)
  • / li>
  • 日志文件过期(在文件过期后删除日志文件)

  • 以平面文本或XML格式输入

  • 文件名格式规范

  • 是否使用日期为文件名前缀

  • 父应用程序名称

  • etc ...

  • 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...

我已经阅读了一些关于DLL程序集的其他stackoverflow问题,它引起app.config之间的冲突托管组件/应用程序。我相信我的程序集只是提供一个配置文件。

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.

这是一个很好的场景吗?这可能是一个更好的主意,我自己的配置到我的项目,以便我的记录器从XML文件读取检索配置值。

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?

推荐答案

<您可以做的是

将程序集的配置放入单独的 MyAssembly.config 文件

put your assembly's configuration into a separate MyAssembly.config file

从主机应用程序的配置引用程序集配置文件:

reference 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆