Mono Class Library: System.Diagnostics NamespaceSystem.Diagnostics.DefaultTraceListener Class |
See Also: DefaultTraceListener Members
System.Object
System.MarshalByRefObject
System.Diagnostics.TraceListener
System.Diagnostics.DefaultTraceListener
|
The DefaultTraceListener is a System.Diagnostics.TraceListener that is present (by default) in all applications. All messages sent through Trace.Write (and related methods) will be sent to the DefaultTraceListener, as well as any other TraceListeners in the Trace.Listeners collection.
There are three ways to view the output of the DefaultTraceListener:
Set the DefaultTraceListener.LogFileName property. This will cause all output to be appended to the specified log file.
This is the only behavior that is consistent across both .NET and Mono platforms.
The LogFileName property can be set either through code, or in the application .config file, by setting the (XPath) /configuration/system.diagnostics/assert/@logfilename attribute. For example:
.config file Example <configuration> <system.diagnostics> <assert logfilename="where I want TraceListener messages to go"/> </system.diagnostics> </configuration>- On Windows, messages are also displayed using the OutputDebugString API. (Look it up on MSDN.) Messages are automatically displayed in the debugger if the program is being debugged. If the program isn't being debugged, a program such as DebugView, available from http://www.sysinternals.com can be used to view the output.
On Unix, the LogFileName property is used, with additional behavior available depending on the MONO_TRACE_LISTENER environment variable.
If MONO_TRACE_LISTENER isn't set or is empty, messages are ignored.
Otherwise, the value in MONO_TRACE_LISTENER must match the following BNF-like grammar:
MONO_TRACE_LISTENER BNF Grammar Example MONO_TRACE_LISTENER := <builtin-locations/> | <file-name/> <builtin-locations/> := ( "Console.Out" | "Console.Error" ) ( ':' <prefix/> )? <prefix/> := any string of characters <file-name/> := any valid file nameConsole.Out corresponds to Standard Output (/dev/stdout), and Console.Error corresponds to Standard Error (/dev/stderr). This also means that you cannot create a filename of Console.Out or Console.Error.
The "prefix" is a string of characters that appears before each message printed to Standard Output or Standard Error. It is not available for filename settings. It is present so that it is easier to distinguish between normal program output and the diagnostic messages.
For example, given the following sample program:
C# Example using System; using System.Diagnostics; public class ShowDefaultTraceListener { public static void Main () { Console.WriteLine ("Standard Output message."); Trace.WriteLine ("TraceListener message"); } }If MONO_TRACE_LISTENER is set to "Console.Out:++prefix++ ", then the output of the program under Unix would be:
Output Example Standard Output message. ++prefix++ TraceListener messageThe DefaultTraceListener is not complete. MSDN specifies that GUI widgets be used for certain features, such as when TraceListener.AssertUiEnabled is true and TraceListener.Fail is called. GUI support is not present, so non-GUI alternatives should be used, such as LogFileName.
The default TraceListener.Name is "Default". The name can be used to remove TraceListeners.
See System.Diagnostics.TraceListener for more information on adding and removing TraceListeners.
[Edit]
Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0