[Mono-list] Diagnostic Messages

Jonathan Pryor jonpryor@vt.edu
26 May 2002 13:39:33 -0400


Comments inline.

On Sun, 2002-05-26 at 13:02, Miguel de Icaza wrote:
    Hello!
    
    > > --diagnostics=[trace | debug | all]
    > 
    > The debug switch shouldn't be on mono/mint, but on mcs instead.
    > A tracing switch should be on both mono/mint and mcs.
    
    This is very interesting.  I did not know about this feature.

Perhaps I'm mis-understanding you, but the feature doesn't exist.  The
current effort is to determine if it *should* exist.  Paul Trunley
raised an interesting alternative of using `syslog' instead.
    
    > By default mcs shouldn't emit code for calls to methods Assert, Fail,
    > Indent, Unindent and the various Write methods on both the Debug and Trace
    > classes. The Debug methods should only be emitted into IL code when you add
    > #define DEBUG to your sourcecode or provide the --define DEBUG switch to
    > mcs. Similarly, the Trace methods should only be emitted into IL code when
    > you add #define TRACE to your sourcecode or provide the --define TRACE
    > switch to mcs. When tracing methods are called from the IL code, by default
    > they'll show their output. Via the application configuration file you can
    > set the trace level or disable tracing completely.
    
    Where can I find these details?  I am very interested in implementing
    these features.

See the System.Diagnostics.ConditionalAttribute documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsConditionalAttributeClassTopic.asp

(Beware line-splitting.)

In short, calls to methods that are marked [Conditional("symbol")] are
only present if the "symbol" is defined.  Thus, if you disassemble the
following program (assuming you compiled it with `csc.exe'):

	using System.Diagnostics;
	public class twl {
		public static void Main () {
			Trace.WriteLine ("Hello, world!");
		}
	}

You'll notice that `System.Diagnostics.Trace' is not referenced in the
generated executable, as it is conditional on TRACE.  The only way to
make it present is to `#define' it in the source code, or pass
`/define:symbol' to `csc.exe'.

Thus, [Conditional("symbol")] is equivalent to the following common C
idiom:

	#ifdef symbol
		#define MACRO(args) /* do something... */
	#else
		#define MACRO(args) /* do nothing */
	#endif

Try it, it's cool.

The application configuration file is another matter that I need to take
a closer look at.
    
    Miguel

 - Jon