Ervis Trupja

Ervis Trupja

  • NA
  • 141
  • 30k

Change value of a Specific Property in app.config using C#

Nov 12 2016 1:04 PM
I want to change the value of <level key="LoggingLevel" value="Test" /> from my app.config file using C#.
App.Config
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="C:\dev\log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="Level - %level%newline" />
</layout>
</appender>
<root>
<level key="LoggingLevel" value="Test" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
 
I want to change the value from Test to Debug using C#. How can I do it?
Thanks in advance. :) 

Answers (2)