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.
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?
You need to make a call to
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>