T
Tony Johansson
Hello!
Here is a complete program.that is using app.config file. I have added this
app.config to the project.
The file app.config looks like this
<?xml version="1.0" encoding="utf-8" ?>
<system.diagnostics>
<switches>
<add name="DataTraceSwitch" value="1"/>
<add name="MessageTraceSwitch" value="3"/>
</switches>
</system.diagnostics>
This program run into ConfigurationErrorException when the first row in
method TestTraceSwitches
is being executed. The Exception dialog box says it was not possible to
initialize the configurationsystem.
Can somebody give me a hint why I get this exception ?
using System;
using System.Collections;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Collections.Generic;
namespace ConsoleApplication20
{
class Program
{
private static TraceSwitch dataSwitch;
private static TraceSwitch messageSwitch;
private static void TestTraceSwitches(int Input)
{
Trace.WriteLineIf(messageSwitch.Level == TraceLevel.Info,
"Entering TestTraceSwitches method.");
Trace.WriteLineIf(dataSwitch.Level == TraceLevel.Info,
"Input: " + Input);
if (Input <= 0)
{
Trace.WriteLine(dataSwitch.Level == TraceLevel.Error,
"Input cannot be less then or equal to 0.");
Trace.WriteLine(messageSwitch.Level == TraceLevel.Error,
"Exception thrown in TestTraceSwitches method.");
throw new ArgumentException("Invalid value.", "Input");
}
Trace.WriteLineIf(messageSwitch.Level == TraceLevel.Info,
"Exiting TestTraceswitches method");
}
static void Main(string[] args)
{
dataSwitch = new TraceSwitch("DataTraceSwitch",
"Display argument information.");
messageSwitch = new TraceSwitch("MessageTraceSwitch",
"Display method calling information.");
TestTraceSwitches(0);
}
}
}
Here is a complete program.that is using app.config file. I have added this
app.config to the project.
The file app.config looks like this
<?xml version="1.0" encoding="utf-8" ?>
<system.diagnostics>
<switches>
<add name="DataTraceSwitch" value="1"/>
<add name="MessageTraceSwitch" value="3"/>
</switches>
</system.diagnostics>
This program run into ConfigurationErrorException when the first row in
method TestTraceSwitches
is being executed. The Exception dialog box says it was not possible to
initialize the configurationsystem.
Can somebody give me a hint why I get this exception ?
using System;
using System.Collections;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Collections.Generic;
namespace ConsoleApplication20
{
class Program
{
private static TraceSwitch dataSwitch;
private static TraceSwitch messageSwitch;
private static void TestTraceSwitches(int Input)
{
Trace.WriteLineIf(messageSwitch.Level == TraceLevel.Info,
"Entering TestTraceSwitches method.");
Trace.WriteLineIf(dataSwitch.Level == TraceLevel.Info,
"Input: " + Input);
if (Input <= 0)
{
Trace.WriteLine(dataSwitch.Level == TraceLevel.Error,
"Input cannot be less then or equal to 0.");
Trace.WriteLine(messageSwitch.Level == TraceLevel.Error,
"Exception thrown in TestTraceSwitches method.");
throw new ArgumentException("Invalid value.", "Input");
}
Trace.WriteLineIf(messageSwitch.Level == TraceLevel.Info,
"Exiting TestTraceswitches method");
}
static void Main(string[] args)
{
dataSwitch = new TraceSwitch("DataTraceSwitch",
"Display argument information.");
messageSwitch = new TraceSwitch("MessageTraceSwitch",
"Display method calling information.");
TestTraceSwitches(0);
}
}
}