Question

I have created a library for event logging utilities using system.Diagnostics like the one below:

public class Logger
{
    static TraceSource ts = new TraceSource("TestApp");
    public void Log(string message)
    {
        ts.TraceEvent(TraceEventType.Verbose, 0, message);
    }
}

I want to use this Log function in my app and other components (dll) of the same application. I tried declaring listeners in app.config of my application, but it didnt work :(. My app.config looks like below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <trace autoflush="true"/>
    <sources>
      <source name="TestApp"
              switchName="mySwitch"
              switchType="System.Diagnostics.SourceSwitch" >
        <listeners>
          <clear/>
          <add name="EventLogListener"
            type="System.Diagnostics.EventLogTraceListener"
            initializeData="Title for events" />
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="mySwitch" value="Verbose" />
    </switches>
  </system.diagnostics>
</configuration>

If i move the class Logger in the application itself (the executable), with the given manifest file, i could see the logs in the application channed in the eventviewer. But i dont want to use it this way.

Can someone please help me find out what is the underlying problem here?

No correct solution

OTHER TIPS

I realized that "Trace" was not enabled for the class library in the csproj. After enabling that i am at least seeing those events in textwriterListener/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top