Link to home
Create AccountLog in
Avatar of wademi
wademi

asked on

Need hep with logger class

I have a logger class like the following

   public class MyLogger
    {
        StreamWriter sw;

        public MyLogger(string LogBase)
        {
            sw = new StreamWriter(string.Format(@"{0}\{1}.LOG", LogBase, DateTime.Now.ToString("yyyy-MM-dd")), true);
        }

        public void WriteToLog(string LogMessage)
        {
            sw.WriteLine(string.Format("{0}, {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm"), LogMessage));

        }

        public void Close()
        {
            sw.Close();
            sw.Dispose();
        }
    }



I have the following in my Main code

     static private void filecheck()

        {
              MyLogger logger = new MyLogger(@"C:\Templogger");
              logger.WriteToLog("Test");

The log file is created when the application is run but its empty. Can anyone see the problem with the code to explain why the word "Test" is not written to the log file?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of wademi
wademi

ASKER

That was it. You are the man. LOL
Glad to help  :)