All pastes #77013 Raw Edit

Something

public text v1 · immutable
·published 2006-07-02 13:11 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Stephen.Tools
{
    public static class Log
    {

        #region Variables

        //Static! 
        public static FileStream file;
        public static StreamWriter stream;
        public static Boolean FileOpen;
        public static Boolean UseConsole = true;

        #endregion

        #region Static Functions

        //Open File
        public static void OpenFile(String _File)
        {

            //Open file..
            file = new FileStream(_File, FileMode.Append, FileAccess.Write);

            //Stream
            stream = new StreamWriter(file);

            //Remember we've opened
            FileOpen = true;

            //Debug
            WriteLine("|| Log Opened;");

        }

        //Close File
        public static void CloseFile()
        {

            //Debug
            WriteLine("|| Log Closing...");

            //Close
            file.Close();

        }

        //WriteLine - Write to Log
        public static void WriteLine(String _Str)
        {

            //File open?
            if (FileOpen)
            {

                //Write to file
                stream.WriteLine(_Str);

            }

            //If enabled, to console too
            if (UseConsole)
            {

                //Write to console
                Console.WriteLine(_Str);

            }

        }

        //Write - Write to Log
        public static void Write(String _Str)
        {

            //File open?
            if (FileOpen)
            {

                //Write to file
                stream.Write(_Str);

            }

            //If enabled, to console too
            if (UseConsole)
            {

                //Write to console
                Console.Write(_Str);

            }

        }

        #endregion

    }
}