指示库需要哪些配置值的最佳方法

发布于 2024-12-04 11:18:50 字数 824 浏览 2 评论 0原文

  • 您实现了一个名为 LogLibrary 的库,它需要配置值,
  • 要检索您实现自己的 System.Configuration.IConfigurationSectionHandler 的配置值,
  • 因此在 App.config<使用 LogLibrary 的程序的 /code> 文件,您希望找到类似以下内容:
<configuration>
    <configSections>
        <section name="LogLibrary" type="Class, Namespace"/>
    </configSections>
    <LogLibrary>
        <!-- Directory where daily log files will be created. -->
        <LogDirectory>C:\Logs</LogDirectory>
        <!-- Insert other values here -->
    </LogLibrary>
</configuration>

问题:向 LogLibrary 用户指示需要做什么的最佳方式是什么存在于App.config

我个人随库提供了一个 README.txt 文件(包含在库的 VS 项目中)。但我发现这个解决方案是“业余的”。你们有更好的做法吗?

  • You implement a Library called LogLibrary which needs configuration values,
  • To retrieve the configuration values you implement your own System.Configuration.IConfigurationSectionHandler,
  • So in the App.config file of the Program using LogLibrary, you want to find something like:
<configuration>
    <configSections>
        <section name="LogLibrary" type="Class, Namespace"/>
    </configSections>
    <LogLibrary>
        <!-- Directory where daily log files will be created. -->
        <LogDirectory>C:\Logs</LogDirectory>
        <!-- Insert other values here -->
    </LogLibrary>
</configuration>

Question: What is the best way to indicate to the users of the LogLibrary what needs to be present in App.config ?

I personally provide a README.txt file (included in the Library's VS project) with the Library. But i find this solution to be "amateur". Do you guys have better practices ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傾城如夢未必闌珊 2024-12-11 11:18:50

您不需要 readme.txt,只需在您的库中包含一个 app.config 以及上面所示的示例值,并在文档中提及这一点。开发人员会在您的源文件或您在线或离线提供的文档中注意到这一点,并将在其 app.config 或 web.config 中复制该部分(与上面相同)。

这就是 Log4Net 的通常情况,您可以通过 google 搜索并在他们的网站上找到示例。

You would not need a readme.txt, just include an app.config in your library with sample values as you have shown above and mention this in the documentation. Developers will notice this either in your source file or in the documentation you provide online or offline and will copy that section (same as above) in their app.config or web.config.

This is how it normally goes for Log4Net, that you google and find examples on their websites.

岛歌少女 2024-12-11 11:18:50

在 .NET 世界中,.config 文件是配置应用程序/库的惯用方式,因此实际位置几乎是给定的。至于配置部分的布局,没有什么比完整的项目文档更好的了(然而现在很少见)。想想NLog 配置文件

In .NET world .config files are idiomatic way of configuring applications/libraries, so actual location is pretty much a given. As for configuration section layout nothing can beat thorough documentation of your project (rare nowadays, however). Think NLog Configuration File.

2024-12-11 11:18:50

我希望库在加载配置时抛出异常,并提供有关存在哪些配置错误的详细信息。与任何库一样,您当然还应该提供适当的文档,其中可以详细说明配置要求。

I would expect the library to throw an exception when loading the configuration with detailed information about what configuration errors are present. As with any library you should of course also supply proper documentation, in which the configuration requirements can be detailed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文