Share via


.NET Samples - How To: Diagnostics

This section includes the following samples:

LogInfo Sample

LogWrite Sample

Trace Sample

Switches Sample

TraceDemo Sample

LogMonitor Sample

PCWrite Sample

PrInfo Sample

ProcessDemo Sample

PCDemo Sample

PCRead Sample

LogInfo Sample

This sample illustrates how to enumerate entries in an event log.

Namespaces used in this sample:

System; System.Diagnostics

Classes used in this sample:

Console; EventLog; Message; Environment; EventLogEntry; String

LogWrite Sample

This sample shows you how to write to an event log.

Namespaces used in this sample:

System; System.Diagnostics

Classes used in this sample:

Console; EventLog; Type; Environment; EventLogEntry; String

Trace Sample

This sample illustrates the basics of using the Trace and Debug classes.

Namespaces used in this sample:

System; System.Diagnostics

Classes used in this sample:

Trace; Debug; TextWriter; TraceListener; TextWriterTraceListener; Console; String

Switches Sample

This sample illustrates the basics of using the TraceSwitch and BooleanSwitch trace switches.

Namespaces used in this sample:

System; System.Diagnostics; System.IO

Classes used in this sample:

Switch; Trace; Debug; TraceSwitch; TraceListener; BooleanSwitch; EventLog; TextWriter; TextWriterTraceListener; Console; EventLogTraceListener; File; String

TraceDemo Sample

This sample illustrates the basics of instrumenting applications with tracing.

Namespaces used in this sample:

System; System.Diagnostics; System.IO

Classes used in this sample:

Trace; Switch; Console; TraceSwitch; BooleanSwitch; TraceListener; TextWriterTraceListener; TextWriter; Debug; Operation; String

LogMonitor Sample

This sample illustrates how to monitor an event log for new entries.

Namespaces used in this sample:

System; System.Threading; System.Diagnostics

Classes used in this sample:

Console; EventLog; Thread; EntryWrittenEventArgs; Environment; Object; EventHandler; Message; EntryWrittenEventHandler; Monitor; String; EventArgs

PCWrite Sample

This sample illustrates writing information to a custom performance counter.

Namespaces used in this sample:

System; System.Threading; System.Diagnostics

Classes used in this sample:

Console; PerformanceCounter; PerformanceCounterCategory; Environment; Object; Thread

PrInfo Sample

This sample illustrates how to get simple information about a process.

Namespaces used in this sample:

System; System.Threading; System.Diagnostics

Classes used in this sample:

Console; Process; Page; String; Environment; ProcessInfo; Thread

ProcessDemo Sample

This sample illustrates how to start and stop an executable.

Namespaces used in this sample:

System; System.Threading; System.Diagnostics

Classes used in this sample:

Process; File; Thread; Console; Environment; String

PCDemo Sample

This sample illustrates how to publish the number of orders processed per second using a custom performance counter.

Namespaces used in this sample:

System; System.Timers; System.Threading; System.Diagnostics

Classes used in this sample:

Timer; Console; PerformanceCounter; CounterCreationData; PerformanceCounterCategory; Exception; Object; CounterCreationDataCollection; Type; Thread; Math; ElapsedEventHandler; EventHandler; EventArgs; ElapsedEventArgs

PCRead Sample

This sample illustrates how to read simple performance information from a performance counter.

Namespaces used in this sample:

System; System.Timers; System.Threading; System.Diagnostics

Classes used in this sample:

Timer; Console; PerformanceCounter; Object; PerformanceCounterCategory; Thread; EventHandler; ElapsedEventArgs; Instance; ElapsedEventHandler; Environment; String; EventArgs