TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Andy Webster
NA
117
0
Updating system.diagnostics section in config file
Jan 19 2012 8:19 AM
Hi
Can anyone help me with how to update the system.diagnostics section of an application configuration file?
Specifically I want to be able to update the trace switch levels held in the config file from code.
Here is the format of the app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="2">
<listeners>
<!-- Optional field, trace listener to accept debug messages and detailed exception information -->
<add name="XML" type="TraceListeners.XmlTraceListener, TraceListeners" />
</listeners>
</trace>
<switches>
<!-- This switch controls tracing, possible values are:
0 = Off
1 = Errors
2 = Errors and warnings
3 = Errors, warnings and information
4 = Verbose (Errors, warnings, information & deep detail debug tracing.)
-->
<add name="TsMain" value="4" />
<add name="TsInit" value="4" />
</switches>
</system.diagnostics>
</configuration>
I want to be able to update the TsMain and TsInit trace levels from code using the System.Configuration namespace rather than directly manipulating the xml through code.
I tried:
Configuration
config =
ConfigurationManager
.OpenExeConfiguration(
ConfigurationUserLevel
.None);
ConfigurationSection
systemDiagnostics = config.GetSection(
"system.diagnostics"
);
But I cannot access the key value pairs for the switches. What I want to do is something like:
systemDiagnostics.Switches.Key["TsMain"].Value = 2;
Any help with this greatfully received.
Reply
Answers (
2
)
CONVERT XML file encoding with UTF-8 into UTF-16 in c#
EXCEPTION HANDLING