Tracing To A File

image_pdfimage_print
   

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 * Version: 1
 */
using System;
using System.IO;
using System.Diagnostics;


namespace Client.Chapter_16___Debugging
{
  public class TracingToAFile
  {
    [STAThread]
    static void Main(string[] args)
    {
      FileStream Log = new FileStream("Log.txt", FileMode.OpenOrCreate);

      Trace.Listeners.Add(new TextWriterTraceListener(Log));
      Trace.WriteLine("My Trace String To Log File");
      Trace.Flush();
      Log.Close();
    }
  }
}

           
          


Trace class: listener and writeline

image_pdfimage_print
   

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 * Version: 1
 */
using System;
using System.IO;
using System.Diagnostics;


namespace Client.Chapter_16___Debugging
{
  public class Class1Chapter_16___Debugging1
  {
    [STAThread]
    static void Main(string[] args)
    {
      Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

      Trace.WriteLine("My Trace to the console");
      
        }
  }
}

           
          


Trace to debuger: writeline and flush

image_pdfimage_print
   

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 * Version: 1
 */
using System;
using System.IO;
using System.Diagnostics;


namespace Client.Chapter_16___Debugging
{
  public class TracingToDebugger
  {
    [STAThread]
    static void Main(string[] args)
    {
      Trace.WriteLine("My Trace String");
      Trace.Flush();
    }
  }
}

           
          


Trace to event log

image_pdfimage_print
   

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 * Version: 1
 */
using System;
using System.IO;
using System.Diagnostics;


namespace Client.Chapter_16___Debugging
{
  public class TracingToEventLog
  {
    [STAThread]
    static void Main(string[] args)
    {
      //You can change the listener with the following code
      EventLogTraceListener EventListener = new EventLogTraceListener("MyApp");

      Trace.Listeners.Add(EventListener);
      
      Trace.WriteLine("My Trace String To Console");

      
        }
  }

}

           
          


Debug class

image_pdfimage_print
   

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 * Version: 1
 */
using System;
using System.IO;
using System.Diagnostics;

namespace Client.Chapter_16___Debugging
{
  public class Class1Chapter_16___Debugging
  {
    [STAThread]
    static void Main(string[] args)
    {
      int i = 0;

      Trace.Assert((i == 1), "My Trace Assertion");
      Debug.Assert((i == 1), "My Debug Assertion");
    }
  }
}

           
          


use the AddYears(), AddMonths(), AddDays(), AddMinutes(), and AddSeconds() methods to add periods to a DateTime

image_pdfimage_print
   
 

using System;

class MainClass {

    public static void Main() {
        DateTime myDateTime9 = new DateTime(2004, 1, 1);
        Console.WriteLine("Initial myDateTime9 = " + myDateTime9);
        myDateTime9 = myDateTime9.AddYears(1);
        myDateTime9 = myDateTime9.AddMonths(5);
        myDateTime9 = myDateTime9.AddDays(3);
        myDateTime9 = myDateTime9.AddMinutes(30);
        myDateTime9 = myDateTime9.AddSeconds(15);
        Console.WriteLine("Final myDateTime9 = " + myDateTime9);

    }
}