none
Getting Trace.WriteLine to work RRS feed

  • Question

  • I've been reading through how to write out to a log file in my .Net application. So, from what I read, I can go into my app.config file and do this:

     <system.diagnostics>
        <sharedListeners>
          <add type="System.Diagnostics.TextWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="TraceFile" initializeData="C:\Mydirectory\MyTraceLog.txt">
            <filter type=""/>
          </add>
        </sharedListeners>
        <trace autoflush="true"/>
      </system.diagnostics> 

    Then, in my code, all I have to do is do a :

    Trace.WriteLine("My text");

    and what should happen is that it will use my referenced TextWriterTraceListener to write to my log.

    Apparently there is more to it than this because the trace is written to the output window but not to the .txt file.

    How to I make the log go the text file?

    Thanks!

        <

    sharedListeners>

          <

    addtype="System.Diagnostics.TextWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"name="TraceFile"initializeData="C:\LHClientTraces\LHTraceLog.txt">

            <

    filtertype=""/>

          </

    add>

        </

    sharedListeners>



        <

    traceautoflush="true"/>

      </

    system.diagnostics>


    STom

    Thursday, January 10, 2013 1:19 AM

Answers

  • Try change the configuration to as below that should make it work.

        <system.diagnostics>
          <trace autoflush="true" indentsize="4">
            <listeners>
              <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Temp\output.log" />
              <remove name="Default" />
            </listeners>
          </trace>
        </system.diagnostics>

    • Proposed as answer by O. Hauch Friday, January 11, 2013 10:08 AM
    • Marked as answer by stombiztalker Friday, January 11, 2013 11:48 AM
    Thursday, January 10, 2013 6:40 AM