1

We have an app.config we are using with Carbonator:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="carbonator" type="Crypton.Carbonator.Config.CarbonatorSection, Crypton.Carbonator"/>
  </configSections>

  <carbonator defaultCulture="en-US" logLevel="1" collectionInterval="1000" reportingInterval="1000" >
    <statsd server="127.0.0.1" port="8125" />
    <counters>
      <add path="processor_information.pct_processor_time.total" category="Processor" counter="% Processor Time" instance="_Total" />
      <add path="memory.available_MBytes" category="Memory" counter="Available MBytes" instance="" />
      <add path="memory.pct_commited_bytes_in_use" category="Memory" counter="% Committed Bytes In Use" instance="" />
    </counters>
  </carbonator>
</configuration>

We want to allow users to configure their own custom counters in an external config file that we reference from the <counters> element. For example, we would like to allow the user config file to look like:

<add path="logical_disk.pct_free_space.C" category="LogicalDisk" counter="% Free Space" instance="C:" />
<add path="logical_disk.disk_read_bytes_per_sec.C" category="LogicalDisk" counter="Disk Read Bytes/sec" instance="C:" />
<add path="logical_disk.disk_write_bytes_per_sec.C" category="LogicalDisk" counter="Disk Write Bytes/sec" instance="C:" />

I don't even know if this is possible outside of an appConfig element, but any help is appreciated.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
lhoworko
  • 1,191
  • 2
  • 13
  • 24

1 Answers1

3

According to this answer it should be possible. Same way is also described in this article.

But I don't think it's a good idea for one reason - if a user makes a mistake in his configuration extension, it will prevent the application from executing since the application configuration became invalid.

I would rather use the configuration in the app.config file to provide default values and implement some user configuration myself. Is such case, you can use whatever configuration format you like, for example JSON, which would be also better (easier to create and edit) for users. In your application, you simply merge both configurations (app.config values are default values which will be overwritten by the user's configuration).

Community
  • 1
  • 1
David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
  • Thanks for the answer. We are still investigating the best approach but I'll keep your suggestions in mind. – lhoworko Apr 29 '16 at 14:27
  • You're welcome. I would definitely implement the custom configuration for the user configuration because you can control everything. You can present better error messages to the user (actually meaningful messages, since default error messages about malformed `app.config` may be pretty confusing for the user). – David Ferenczy Rogožan Apr 29 '16 at 16:03