Search code examples
c#asp.netdlltracesystem.diagnostics

Traces into DLL


I have a referenced dll to my project with traces using the TraceSource and it´s not working. My code in the dll project is something like this:

private static readonly TraceSource ts = new TraceSource("DataSource");
...
ts.TraceInformation(string.Format("Info: {0}", mess));

In the application project (where I import the DLL) the App.config:

<system.diagnostics>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add name="MyListener" />
        <remove name="Default" />
      </listeners>
    </trace>

    <sources>
      <source name="DataSource" switchValue="All">
        <listeners>
          <remove name="Default"/>
          <add name="MyListener"/>
        </listeners>
      </source>
    </sources>

    <sharedListeners>
      <add name="MyListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="c:\\temp\DefaultWriterOutput.log" />

    </sharedListeners>
  </system.diagnostics>

When I use a referenced project with the traces, all is working fine, but when I import the dll the trace is not working. Is there something wrong in the configuration?


Solution

  • I forgot that my DLL project is using a Nuget configuration (not Release). :( I set the  TRACE constant in the project properties into Nuget configuration and it works.