A Guided Garden Stroll through the .NET Framework Class Library
Namespace: SYSTEM.DIAGNOSTICS
● I am the Diagnostics Namespace. My most famous classes are Debug*, EventLog* and Trace.
I, the Diagnostics namespace, allows you to easily capture error information both during debugging use and during production use of your application.
For recording error conditions in a server based application, the application EventLog is ideal. To record errors in the EventLog use my Diagnostics.EventLog.WriteEntry method.
For business applications, you will want to write to the Windows 2000, XP or .NET Server "Application" Event log. Before calling EventLog.WriteEntry, be sure you register a source name that identifies your application in the Event log. To see if that source name exists already, call EventLog.SourceExists. If SourceExists returns False, then call EventLog.CreateEventSource to add a source name (once per server), and proceed to log the error by calling the EventLog.WriteEntry method. Note that your application will need registry permission to create a new source name.
Simply call Debug.WriteLine with a string containing the debug information and that information will appear in the Visual Studio Output Window. Like VB6, Debug code is produced and executed only if you compile your project into a Debug Build, otherwise no Debug code is generated. So leave your Debug.WriteLine method calls in your deployed code.
Use my Trace class to record information about how your program is executing. Unlike Debug, Trace code stays in your production application after deployment and is enabled by default. By using a dynamic property setting in your applications config file and my TraceSwitch class, you can have Tracing enabled or disabled or produce different levels of trace information at runtime, all without recompiling and redeploying your application.
You can direct Trace and Debug information to different output devices or files, including the event log, by simply adding a new Listener object to the Trace.Listeners or Debug.Listeners collection.
I, the Diagnostics namespace, am quite extensive. With my ConditionalAttribute class your application can test-for and branch based on Compile time attributes you define. Also, you can start and stop system processes and monitor running processes with my Process class, monitor and work with system performance counters and get StackTrace and StackFrame information.