Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Read config file with OpenExeConfiguration? [modified]

Read config file with OpenExeConfiguration? [modified]

Scheduled Pinned Locked Moved C#
tutorialdebuggingxmlquestionworkspace
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus_2
    wrote on last edited by
    #1

    Hello. Right now I admit defeat and don't know how to do this. I have a configuration file that I have to load at runtime and interpret. This works fine for all the settings in the appSettings sections but I don't know how to get the value from the system.diagnostics section. This is an example of an config file (in "real" a lot bigger;))

    <configuration>
    <appSettings>
    <add key="Hello" value="World" />
    </appSettings>

    <system.diagnostics>
    <switches>
    <add name="Trace" value="4" />
    </switches>
    </system.diagnostics>

    </configuration>

    To load the file I use the OpenExeConfiguration method and most of the data I can get to, but not the "Trace" value from the system.diagnostics.

    // Get the configuration file.
    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration("c:\\projext1.exe");
    
    MessageBox.Show(config.AppSettings.Settings["Hello"].Value);  //this shows OK
    
    ConfigurationSection sel = config.Sections["system.diagnostics"]; // Here I find the section, but then...  ???
    

    Does anybody have any idea on how to get the value? A possible solution might be to load the file into XML, but I'm still hoping on using the Configuration object. Hope you can stand my bad english and thanks to enybody that have a suggestion. Edit: formatting... :sigh:

    Mircea PuiuM 1 Reply Last reply
    0
    • M Marcus_2

      Hello. Right now I admit defeat and don't know how to do this. I have a configuration file that I have to load at runtime and interpret. This works fine for all the settings in the appSettings sections but I don't know how to get the value from the system.diagnostics section. This is an example of an config file (in "real" a lot bigger;))

      <configuration>
      <appSettings>
      <add key="Hello" value="World" />
      </appSettings>

      <system.diagnostics>
      <switches>
      <add name="Trace" value="4" />
      </switches>
      </system.diagnostics>

      </configuration>

      To load the file I use the OpenExeConfiguration method and most of the data I can get to, but not the "Trace" value from the system.diagnostics.

      // Get the configuration file.
      System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration("c:\\projext1.exe");
      
      MessageBox.Show(config.AppSettings.Settings["Hello"].Value);  //this shows OK
      
      ConfigurationSection sel = config.Sections["system.diagnostics"]; // Here I find the section, but then...  ???
      

      Does anybody have any idea on how to get the value? A possible solution might be to load the file into XML, but I'm still hoping on using the Configuration object. Hope you can stand my bad english and thanks to enybody that have a suggestion. Edit: formatting... :sigh:

      Mircea PuiuM Offline
      Mircea PuiuM Offline
      Mircea Puiu
      wrote on last edited by
      #2

      Be sure that you are: using System.Diagnostics Then, in your code, you can use the configured switch by creating a TraceSwitch with the same name as in your config file: TraceSwitch appSwitch = new TraceSwitch("Trace", ""); The value you want to retrieve is appSwitch.Level (which in your case will be Verbose, as you have the value set to 4 in your **config file.

      SkyWalker

      **

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups