| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //
- // System.Diagnostics.TraceImpl.cs
- //
- // Authors:
- // Jonathan Pryor ([email protected])
- //
- // (C) 2002 Jonathan Pryor
- //
- using System;
- using System.Diagnostics;
- namespace System.Diagnostics {
- internal class TraceImpl {
- private static object lock_ = new object ();
- private static bool autoFlush = false;
- public static bool AutoFlush {
- get {return autoFlush;}
- set {autoFlush = value;}
- }
- // FIXME: From MSDN: "This property is stored on
- // per-thread/pre-reqeust basis"
- //
- // What exactly does this mean? Sure, we can mark it
- // [ThreadStatic], which make a per-thread value, but what
- // does this mean for each of the writers? Do *they* need to
- // store this as a thread-static value?
- [MonoTODO, ThreadStatic]
- private static int indentLevel = 0;
- public static int IndentLevel {
- get {return indentLevel;}
- set {indentLevel = value;}
- }
- // FIXME: From MSDN: "This property is stored on
- // per-thread/pre-reqeust basis"
- //
- // What exactly does this mean? Sure, we can mark it
- // [ThreadStatic], which makes a per-thread value, but what
- // does this mean for each of the writers? Do *they* need to
- // store this as a thread-static value?
- [MonoTODO, ThreadStatic]
- private static int indentSize = 4;
- public static int IndentSize {
- get {return indentSize;}
- set {indentSize = value;}
- }
- private static TraceListenerCollection listeners =
- new TraceListenerCollection ();
- public static TraceListenerCollection Listeners {
- get {return listeners;}
- }
- // FIXME: According to MSDN, this method should display a dialog box
- [MonoTODO]
- public static void Assert (bool condition)
- {
- if (!condition)
- Fail (new StackTrace().ToString());
- }
- // FIXME: According to MSDN, this method should display a dialog box
- [MonoTODO]
- public static void Assert (bool condition, string message)
- {
- if (!condition)
- Fail (message);
- }
- // FIXME: According to MSDN, this method should display a dialog box
- [MonoTODO]
- public static void Assert (bool condition, string message,
- string detailMessage)
- {
- if (!condition)
- Fail (message, detailMessage);
- }
- public static void Close ()
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.Close ();
- }
- }
- }
- // FIXME: From testing .NET, this method should display a dialog
- [MonoTODO]
- public static void Fail (string message)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.Fail (message);
- }
- }
- }
- // FIXME: From testing .NET, this method should display a dialog
- [MonoTODO]
- public static void Fail (string message, string detailMessage)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.Fail (message, detailMessage);
- }
- }
- }
- public static void Flush ()
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners){
- listener.Flush ();
- }
- }
- }
- public static void Indent ()
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.IndentLevel++;
- }
- }
- }
- public static void Unindent ()
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.IndentLevel--;
- }
- }
- }
- public static void Write (object value)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.Write (value);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void Write (string message)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.Write (message);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void Write (object value, string category)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.Write (value, category);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void Write (string message, string category)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.Write (message, category);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void WriteIf (bool condition, object value)
- {
- if (condition)
- Write (value);
- }
- public static void WriteIf (bool condition, string message)
- {
- if (condition)
- Write (message);
- }
- public static void WriteIf (bool condition, object value,
- string category)
- {
- if (condition)
- Write (value, category);
- }
- public static void WriteIf (bool condition, string message,
- string category)
- {
- if (condition)
- Write (message, category);
- }
- public static void WriteLine (object value)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.WriteLine (value);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void WriteLine (string message)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.WriteLine (message);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void WriteLine (object value, string category)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.WriteLine (value, category);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void WriteLine (string message, string category)
- {
- lock (lock_) {
- foreach (TraceListener listener in Listeners) {
- listener.WriteLine (message, category);
- if (AutoFlush)
- listener.Flush ();
- }
- }
- }
- public static void WriteLineIf (bool condition, object value)
- {
- if (condition)
- WriteLine (value);
- }
- public static void WriteLineIf (bool condition, string message)
- {
- if (condition)
- WriteLine (message);
- }
- public static void WriteLineIf (bool condition, object value,
- string category)
- {
- if (condition)
- WriteLine (value, category);
- }
- public static void WriteLineIf (bool condition, string message,
- string category)
- {
- if (condition)
- WriteLine (message, category);
- }
- }
- }
|