-1

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?

  • Superficially the app settings file looks fine. Try a different listener, say a file listener and see if it isn't related to the EventLog (which can have permissions challenges, challenges related to if you are logging to an existing event category or a new one). I don't understand your last paragraph at all. It works (makes logs visible or channeled in an event viewer) after doing something (unclear) but you don't want it to work that way? What way do you want it to work? – MatthewMartin Mar 03 '14 at 19:59
  • What i meant in the last paragraph that if i don't have logger as part of a separate library and put all its code within the one single console application, it works fine. I can see the logs getting published in the event channel. – user3375881 Mar 03 '14 at 20:45

1 Answers1

2

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/