Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF trace file keeps getting corrupted?

Tags:

c#

.net

iis

trace

wcf

I enabled message tracing on a WCF service. it traces a couple of messages and then it stops, when I try to open the trace in TraceViwer it gives me an error on the last message that got logged, or doesn't even open the file duo to different error everytime.

I can't even delete the corrupt file unless i run a resetiis since the file is being used!

here is my trace config.

<system.diagnostics>
        <sources>
            <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
                <listeners>
                    <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                    </add>
                    <add name="ServiceModelMessageLoggingListener">
                        <filter type="" />
                    </add>
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add initializeData="C:\Logs\Web_messages.svclog"
              type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
              name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
                <filter type="" />
            </add>
        </sharedListeners>
    </system.diagnostics>

<system.serviceModel>
    <diagnostics>
        <messageLogging logEntireMessage="true" logMalformedMessages="true"
          logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
</system.serviceModel>
like image 833
kay.one Avatar asked Jul 06 '09 20:07

kay.one


2 Answers

Per John's answer, you can use Trace.AutoFlush to flush the file after every write. Something along the lines of this example ...

<system.diagnostics>
   <sources>
       <source name="UserTraceSource" switchValue="Warning, ActivityTracing" >
          <listeners>
              <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="C:\logs\UserTraces.svclog" />
          </listeners>
       </source>
   </sources>
   <trace autoflush="true" /> 
</system.diagnostics>
like image 107
JP Alioto Avatar answered Nov 06 '22 02:11

JP Alioto


Is the service still running? Then the problem may simply be that the file has not been flushed yet.

like image 28
John Saunders Avatar answered Nov 06 '22 01:11

John Saunders