none
WCF Custom message RRS feed

  • Question

  • How can I add my own messages to WCF  flat log file , not to the svc log file. 

    Trace.WriteLine ("Hell0") . I want this message to appear in my log file

     <system.diagnostics>
            <trace autoflush="true" />
            <sources>
                <source name="System.ServiceModel.MessageLogging"
                        switchValue="Verbose">
                   
                    <listeners>
                        <add name="ARICListner"
                            type="System.Diagnostics.TextWriterTraceListener"
                            initializeData="c:\temp\WCF.Log"  />
                    </listeners>

                </source>
            </sources>
        </system.diagnostics>


    NV

    Friday, September 6, 2013 5:06 PM

Answers

  • Remove removes the instance of the DefaultTraceListener class that is automatically added to the Debug.Listeners and Trace.Listeners collections. The following configuration should also work but then you will also see the trace messages in the Output window:

      <system.diagnostics>
        <trace autoflush="true" indentsize="4">
          <listeners>
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextWriterOutput.log" />
          </listeners>
        </trace>
      </system.diagnostics>
    

    • Marked as answer by nik0812 Saturday, September 7, 2013 3:00 PM
    Saturday, September 7, 2013 9:21 AM

All replies

  • You should add a <messageLogging> element to enable tracing at message level as described here:
    http://a1ashiish-csharp.blogspot.com/2013/05/csharp-.net-wcf-how-to-enable-wcf-tracing-and-MessageLogging.html
    Friday, September 6, 2013 6:13 PM
  • Thanks for the reply. Aritcle is really good but it doesn't answer my question.

    I don't want to trace the messages at Transport or Service level. I just want to trace What I have written in code for Tracing like 

    Trace.Writeline("Process Started");

    Trace.Writeline("Process is executing");

    Trace.writeline("Process end"); 

    I want to see only above 3 lines in my log file . How should I do that ?


    NV

    Friday, September 6, 2013 8:23 PM
  • Try the following <system.diagnostics> configuration:

    <system.diagnostics>
        <trace autoflush="true" indentsize="4">
          <listeners>
            <add name="ARICListner" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\temp\WCF.Log" />
            <remove name="Default" />
          </listeners>
        </trace>
      </system.diagnostics>

    http://msdn.microsoft.com/en-us/library/sk36c28t.aspx

    Friday, September 6, 2013 8:55 PM
  • Yes Above configuration works for me . Thanks. Is the Remove tag does the trick?

    NV

    Friday, September 6, 2013 10:02 PM
  • Remove removes the instance of the DefaultTraceListener class that is automatically added to the Debug.Listeners and Trace.Listeners collections. The following configuration should also work but then you will also see the trace messages in the Output window:

      <system.diagnostics>
        <trace autoflush="true" indentsize="4">
          <listeners>
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextWriterOutput.log" />
          </listeners>
        </trace>
      </system.diagnostics>
    

    • Marked as answer by nik0812 Saturday, September 7, 2013 3:00 PM
    Saturday, September 7, 2013 9:21 AM
  • Thank you for clearing my question.

    NV

    Saturday, September 7, 2013 3:00 PM