Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Help Writing a Logger Program (http://www.go4expert.com/forums/help-writing-logger-program-t19804/)

SeanXD 18Oct2009 13:44

Help Writing a Logger Program
 
Our teacher for my 3D Game Programming class has given us a project to create a Logger Class using an Interface to log certain attributes of at least 3 objects in a game we create and to write that information to one text file and output it onto the game screen. He has not given us any information on how to do it and has basically old us to figure it out on our own. It is probably simple, but he has given certain restrictions on how to write it. He does not what he has written to be changed (with the exception of the semi colons at the end of the headers). He has given a basic outline of the logger class and interface with the function headers, but I do not know what to write in them. I do understand that I must use Singleton structures in this program, but I am truly stumped on how to implement it. I am very inexperienced in programming and I really need some help on what to do with this assignment. Here is the text he gave us listing exactly what he wants done and if anyone can send me some sort of rough solution to it, it would be greatly appreciated.

"Implement the following Interface and Class. Comments must be followed. You cannot alter method
signatures. You may add in whatever additional public/protected/private methods or properties you
feel is needed to implement. Also show a simple example of at least 3 objects reporting info to the
logger, both on screen and to a file. The sample does not need to be in 3D.


Run clean build on the sample, zip it up, and turn it in here.

Code:

ILog
{
    //returns the text the object wants to report
    public string Report();
}
 
 
Logger
{
    //Private constructor to enfource Singleton access
    private Logger();
 
    //Draws the current log information to the screen using SpriteBatch.DrawString
    //Need to be called every frame
    public void Draw();   
   
    //takes an object that implements ILog and stores it for later use
    public bool RegisterObject(ILog obj);
   
    //remove the object from the registration data structure
    public bool UnregisterObject(ILog obj);
   
    //removes all objects from the registration data structure
    public void UnregisterAll();
   
    //Starts file logging.  Must not crash or corrupt the file if called twice in a row.
    //file name must be in the format of: gamename-hh-mm-ss-dd-mm-yyyy.txt
    //pattern is hours-minutes-seconds-day-month-year for clarification
    public void StartFileLogging();
   
    //ends file logging.  Must not crash if called before StartFileLogging()
    public void EndFileLogging();
   
    //starts displaying the log info to screen
    public void StartScreenDisplay();
   
    //stops displaying log info to screen
    public void StopScreenDisplay();
   
    //Updates the report data if nessacary.  Update is called every frame, but should
    //only update information every UpdateInterval
    public void Update(GameTime gameTime);
   
    //internal method that actually gathers all the info
    protected void GatherInfo();
   
    //performs the actualy act of writing to the log file
    protected void WriteFile();
   
    //all intervals are in milliseconds
    //interval for writing to file
    public int FileWriteInterval{get; set;};
    //interval for updating log data
    public int UpdateInterval{get; set;};
 
    //defines where to start drawing log info on screen
    public Vector2 DrawLocation;
   
    //returns an instance of Logger
    public static Logger GetInstance{get;};   
   
}"



All times are GMT +5.5. The time now is 16:04.