Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Folks!

I'm currently facing a problem and cannot figure out what's wrong.

In my application, I use a simple Plugin architecture. For debugging, I want to write text to my trace. I have set up a TraceSource within the Plugin.dll:

C#
private static readonly TraceSource ts = new TraceSource("Plugin");


The application app.config contains:

XML
<system.diagnostics>
  <trace autoflush="true" indentsize="4">
    <listeners>
      <add name="defaultLogListener"/>
    </listeners>
  </trace>
		
  <sources>
    <source name="Plugin" switchValue="All">
      <listeners>
	<remove name="Default"/>
	<add name="defaultLogListener"/>
      </listeners>
    </source>
  </sources>
		
  <sharedListeners>
    <add name="defaultLogListener" 
      type="System.Diagnostics.ConsoleTraceListener"
      traceOutputOptions="Timestamp"/>
  </sharedListeners>
</system.diagnostics>


Tracing from within the application works, but I don't get the messages from within the plugin.dll raised by

C#
ts.TraceInformation("TRACE from Plugin");


What am I doing wrong? Do I have to pass a TraceSource from my application to the Plugin instead of creating a new one inside?

Thanks a lot in advance

Rowan
Posted

1 solution

Sometimes ... it's time to slap the head against the wall. :-)

Just a config thing:

My Plugin TraceSource was not writing to the correct listener...

The following config works perfectly, writing to both, file and console listener:

XML
<system.diagnostics>
  <trace autoflush="true" indentsize="4">
    <listeners>
  <add name="defaultLogListener" />
  <add name="defaultFileListener" />
    </listeners>
  </trace>

  <sources>
  <source name="ImporterPlugin" switchvalue="All">
    <listeners>
      <add name="defaultLogListener" />
      <add name="defaultFileListener" />
        </listeners>
  </source>
  </sources>

  <sharedlisteners>
  <add name="defaultLogListener">
       type="System.Diagnostics.ConsoleTraceListener"
       traceOutputOptions="Timestamp"/>
  <add name="defaultFileListener">
       type="System.Diagnostics.TextWriterTraceListener"
       initializeData="application.log" />
  </add></add></sharedlisteners>
</system.diagnostics>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900