I have custom trace listener that logs to a string(which I'll bind to a wpf textbox) which I I'm trying to find in my ViewModelLocator, it (or all of the other listeners I defined) don't seem to be in System.Diagnostics.Trace.Listeners)
App.config snippet
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="RomanExampleWPFAppSwitch" value="Verbose" />
</switches>
<sources>
<source name="RomanExampleWPFApp" switchName="RomanExampleWPFAppSwitch">
<listeners>
<remove name="Default" />
<add name="RollingLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" initializeData="RollingLogWriter" append="true" autoFlush="true" baseFileName="RomanExampleWPFAppLog" location="LocalUserApplicationDirectory" logFileCreationSchedule="Daily" reserveDiskSpace="1073741824" traceOutputOptions="DateTime,LogicalOperationStack" />
<add name="StringLog" type="RomanExampleWPFApp.Other.StringLogTraceListener, RomanExampleWPFApp" />
<add name="consoleListener" type="System.Diagnostics.ConsoleTraceListener" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
Trace messages are received by listeners. The purpose of a listener is to collect, store, and route tracing messages. Listeners direct the tracing output to an appropriate target, such as a log, window, or text file.
By default, the output is written to an instance of DefaultTraceListener. This method calls the WriteLine method of the trace listener.
Diagnostics provides a set of attributes and classes to interact with the system process, event managers, performance counts, etc. This namespace can help us too in debugging jobs. Let's review the useful actions inside System. Diagnostics namespace.
If you can't find it back in the Trace.Listeners collection then you can assume that the listener never got added. Two basic reasons:
You might be debugging with the Visual Studio Hosting Process option enabled. Which uses a different config file, app.vshost.exe.config. Project + Properties, Debug tab to turn it off.
The entry in the .config file might be malformed. You can tell from the Visual Studio Output window, you'll see a "first chance exception" notification. Debug + Exceptions, click the Thrown checkbox to force the debugger to stop when the exception is raised. You can glean info from the stack trace. This exception doesn't otherwise prevent your app from running. We can't guess if the "type" value is accurate.
You are defining a specific TraceSource. If you want to trace something in this case, this is how you would do like this:
TraceSource source = new TraceSource("RomanExampleWPFApp");
source.TraceInformation("hellow world");
And if you want to get a list of listeners, then you can do it like this:
TraceSource source = new TraceSource("RomanExampleWPFApp");
foreach (var listener in source.Listeners)
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With