System.Diagnostics.Trace is not safe.
I always thought that methods exposed by System.Diagnostics.Trace class did something like dispatching messages to the OS and/or to the trace listeners configured for the application. And by dispatching I mean a sort of asynchronous and safe (from exceptions in the listeners if any) delivering of messages.
I don’t know exactly why I had this idea in my mind, but in any case it was a wrong idea. The execution of method like Trace.WriteLine(“my message”) is synchronous, and may generate an exception if something goes wrong in one of the trace listeners currently registered.
I think that this can occurs easily because:
– trace listeners can be simply registered by editing the configuration file.
– you can pass to Trace class methods messages in form of objects, not only strings.
– if your are programming a component you may not have envision of the environment in which your code will run.
I have to start enclose calls to those methods in try – catch blocks. I would like to know: does someone (if there is someone that use this class) already do it?