开发者

Best way to indicate what configuration values are needed by a library

  • 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 wha开发者_Python百科t 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 ?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜