What I'm trying to accomplish is setting a TraceListener for a TraceSource in a referenced .dll using only the config file.
Specifically I have solution Robot which has an app.config that looks like this:
<system.diagnostics>
<sources>
<source name="RobotModel" switchValue="All">
<listeners>
<add name="RobotModelConsole" type="Ukadc.Diagnostics.Listeners.ConsoleTraceListener, Ukadc.Diagnostics" initializeData="{DateTime}::{EventType}::{Message}"/>
</listeners>
</source>
</sources/
and a ExtendedSource (from the Ukadc.Diagnostics.dll) initialized like this:
public static ExtendedSource robotSourceEx = new ExtendedSource( "RobotModel", SourceLevels.All );
Then I export the .dll and import it to the UI component and have a similar app.config:
<system.diagnostics>
<sources>
<source name="Temp" switchValue="All">
<listeners>
<!--<add name="console1" type="System.Diagnostics.ConsoleTraceListener" /> -->
<add name="console" type="Ukadc.Diagnostics.Listeners.ConsoleTraceListener, Ukadc.Diagnostics" initializeData="{DateTime}::{EventType}::{Message}" />
</listeners>
</source>
<source name="RobotModel" switchValue="All">
<listeners>
<add name="console1" type="Ukadc.Diagnostics.Listeners.ConsoleTraceListener, Ukadc.Diagnostics" initializeData="{DateTime}::{EventType}::{Message}" />
</listeners>
</source>
</sources>
When I run the UI component I get an empty console (Console.WriteLine and the trace information is missing), but if i comment out the TraceListener for the RobotModel, then the console has the example trace messages (as well as the Console.WriteLine message).
- Do I somehow need to specify the .dll or namespace for the RobotModel TraceListener
- I know I can do this dynamically as I have a winform component TraceListener that gets the trace messages, but want to configure this from the app.config assuming this is at all possible
Note: the gui is a Winforms/Windows Application while the Robot class is a console application. I don't think this would make a huge difference but maybe its noteworthy. I do manually allocate a console on the Windows Application so that I can ensure the trace works before routing it to a File.