Diagnostics Trace data disappears after exception

Go To StackoverFlow.com

1

I'm using Azure Diagnostics Trace to log messages. The configuration is to transfer the logged data every minute to Azure Storage Table.

While testing the setup I have discovered that in case of unhanded exception, the previous trace data disappears.

For example:

 Trace.WriteLine("T1");
 Trace.WriteLine("T2");
 Trace.WriteLine("T3");

This will show up in the Azure Table after a minute

 Trace.WriteLine("T1");
 Trace.WriteLine("T2");
 Trace.WriteLine("T3");
 throw new TimeoutException();

This will not log the data, because of the exception.

I was under the impression that Diagnostics should persist the data, why is this happening?

2012-04-03 21:46
by Registered User


1

You need to make a call to

Trace.Flush();

to ensure that the data is persisted. The Trace information is buffered in memory, and the exception causes that information to be lost before it even makes it into the diagnostic area that can be picked up by the Azure Table transfer process.

You can also set the autoflush property in your configuration file to ensure the Trace data is automatically flushed after every write:

<system.diagnostics>    
  <trace autoflush="true">
    ...
  </trace>
</system.diagnostics>
2012-04-03 21:47
by mellamokb