kay.one
kay.one

Reputation: 7692

WCF trace file keeps getting corrupted?

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>

Upvotes: 5

Views: 3680

Answers (2)

JP Alioto
JP Alioto

Reputation: 45117

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>

Upvotes: 11

John Saunders
John Saunders

Reputation: 161773

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

Upvotes: 1

Related Questions