Exception in configuration section handler when app is opened concurrently

I have a windows app in c#. In the config file I have the following section:

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

When a single instance of the app is launched everything works just fine,
however, when I launch another instance of the app, an "Exception in
configuration section handler" exception is being throw on the first
attempt to do a Trace.Writeline.
Thanks in advance!

[767 byte] By [zhangg3] at [2007-12-16]
# 1

I believe your issue stems from your application attempting to trace to the same file. The TextWriterTraceListener generates the FileStream with FileShare.Read which prevents the second application from generating the FileStream because it cannot gain write access. You could write a custom trace listener that is aware of the multiple instances, but it would probably be easier to initialize the listener programatically. An alternative to file based tracing would be to write traces to the event log via the EventLogTraceListener. In an environment where there are multiple instances running concurrently I would recommend the event log as instead of file based tracing.

David Banister

DavidBanister at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Thanks for confirming my suspicion. I was kind of hoping the TextWriterTraceListener would be smart enough to detect a stream
had already been open.

This app sits on a app server and I don't have access to view the event log.

Guess the easiest way now is to add the trace listener programmatically.

Thanks!

zhangg3 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified